January 2013
Intermediate to advanced
328 pages
8h 5m
English
Once we have a good start on a grammar, we can integrate the ANTLR-generated code into a larger application. In this section, we’ll look at a simple Java main that invokes our initializer parser and prints out the parse tree like TestRig’s -tree option. Here’s a boilerplate Test.java file that embodies the overall recognizer data flow we saw in Let’s Get Meta!:
| | // import ANTLR's runtime libraries |
| | import org.antlr.v4.runtime.*; |
| | import org.antlr.v4.runtime.tree.*; |
| | |
| | public class Test { |
| | public static void main(String[] args) throws Exception { |
| | // create a CharStream that reads from standard input |
| | ANTLRInputStream input = new ANTLRInputStream(System.in); ... |
Read now
Unlock full access