[antlr-interest] Simple Grammar breaks ANTLRWorks Interpreter & Debugger?

Gavin Lambert antlr at mirality.co.nz
Thu Aug 13 14:22:18 PDT 2009


At 08:56 14/08/2009, consiliens at gmail.com wrote:
 >Thanks for the tip! I marked the appropriate rules as fragments, 

 >however all the issues in the original post still stand. The
 >debugger simply generates a Parse Tree of root -> quiz, while
 >the Interpreter correctly generates the Parse Tree. Is this
 >possibly an issue with ANTLRWorks itself?

Try changing your quiz rule to this:

quiz:
	  multiple_choice* EOF;

Without the EOF, you're saying to ANTLR "if you don't find 
something that matches multiple_choice, that's ok, just 
stop".  With it, you're saying "after you've matched all the 
multiple_choices you can, you must have no input left", which 
means that you'll get an error if there is unconsumed input (which 
would mean that your multiple_choice rule or its descendants 
aren't matching what you're expecting them to).

Tracing it through with either the debugger or a unit test should 
show where the problem lies.  A good thing to try is to write a 
unit test that simply pulls all the generated tokens off the lexer 
and verifies them; if your lexer isn't producing the tokens you're 
expecting then there's little chance the parser will work, and 
unfortunately the ANTLR/ANTLRworks environment isn't really set up 
to test the lexer properly.



More information about the antlr-interest mailing list