0
votes

I am processing my input file through my custom grammar and extracting tokens and returning them in a HashMap. In ANTLR 3 I was able to parse the file by invoking rule() method on parser and getting the HashMap something like parser.record.

This doesn't seems to work in ANTLR 4. I referred the book and it appears that I have to call parser.init() to start parsing but I don't see any method in my parser.

I used ANTLRWorks 2 to generate my lexer and parser files. I didn't generate the listener classes.

1

1 Answers

5
votes

In ANTLR 4, you start parsing by calling the method matching the name of the entry rule. If the rule in your grammar is called rule, you would start parsing by calling rule(). If the rule in your grammar is called init, then you would start parsing by calling init().

Note that the Java target in ANTLR 4 does not allow you to have a rule called rule, so if you have such a rule in your grammar you'll need to rename it before the grammar will compile.