Reputation: 3
I created a grammar called goal.g4
Then, from terminal (on a mac) I launched "java -cp "antlr-4.7.1-complete.jar" org.antlr.v4.Tool goal.g4 -listener -visitor" that terminates correctly.
Then I use the following java code:
input = new ANTLRInputStream(fis); /* where fis is a FileInputStream */
goalLexer lexer = new goalLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
goalParser parser = new goalParser(tokens);
parser.start();
my point is: how to retrieve the ParseTree object from the parser? As suggested I replaced the init() method with the start() methods. However eclipse tells me that parser.start() does not exist...
How do I solve this? Thanks Luca
Upvotes: 0
Views: 335
Reputation: 53337
Look in your grammar. You have to identify the start rule you want to go with. Usually the start rule is near the top of the file and/or is one of the few (or only one) that is not called by any other rule.
Whatever rule you choose it will return a parse tree context, which forms the root of your parse tree, e.g.
ParseTree tree = parser.start();
Upvotes: 1