...
Code Block |
---|
import org.antlr.runtime.*; public class Test { public static void main(String[] args) throws Exception { ANTLRInputStream input = new ANTLRInputStream(System.in); ExprLexer lexer = new ExprLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); ExprParser parser = new ExprParser(tokens); parser.prog(); } } |
Run ANTLR on the grammar and compile:
Code Block |
---|
java org.antlr.Tool Expr.g
javac Test.java ExprLexer.java ExprParser.java
|
Here is a sample run:
No Format |
---|
$java Test x=1 y=2 3*(x+y) <EOF> 9 $ |
...