I recently bought the Ultimate ANTLR Reference , and I am very pleased to start using ANTLR. The first chapter shows this grammar:
grammar T;
options {
language = Java;
}
r : 'call' ID ';' {System.out.println("invoke " + $ID.text);} ;
ID : 'a'..'z'+ ;
WS : (' '|'\n'|'\r')+ {$channel=HIDDEN;} ;
I copied this grammar to a file, (extension .g), generated Lexer and Parser, and created the main class as follows:
import org.antlr.runtime.*;
public final class Test {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
TLexer lexer = new TLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
TParser parser = new TParser(tokens);
parser.r();
}
}
There are no real errors, but when I run the main class and contribute:
call foo;
Nothing happens. "invoke foo" should be displayed, but nothing happens. I do not want to go to a book without doing a single exercise. I use ANTLR 3.4 in Eclipse if that matters. Sorry if this seems like a simple question, but I'm new to ANTLR.
Thanks,
Omer
leaf source
share