I recently purchased The Definitive ANTLR Reference and I am excited to begin using ANTLR.
In the first chapter, this grammar is shown:
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 down into a file, (.g extension), generated the Lexer and Parser, and created a main class like so:
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 enter:
call foo;
Nothing happens. "invoke foo" should be outputted to the screen, but nothing happens. I don't want to go on in the book without completing any one exercise. I'm using ANTLR 3.4 in Eclipse if it matters. Sorry if this seems like an easy question, but I'm new to ANTLR.
Thanks,
Omer