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

consiliens at gmail.com consiliens at gmail.com
Thu Aug 13 14:41:36 PDT 2009


Gavin Lambert wrote:
> 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.
> 
> 
I experimented a bit with EOF. Making your suggested change yields a 
Parse Tree, in the Debugger, of root -> quiz -> EOF. It seems like the 
debugger isn't getting any of the input for some reason.

Doesn't the Parse Tree correctly appearing in ANTLRWorks Interpreter 
allow one to verify the tokens are being produced correctly?

I'll try writing a unit test, as you suggest, and will see what happens.


More information about the antlr-interest mailing list