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

consiliens at gmail.com consiliens at gmail.com
Fri Aug 14 11:55:23 PDT 2009


Gavin Lambert wrote:
> At 10:12 14/08/2009, consiliens at gmail.com wrote:
>  >QuizLexer lexer = new QuizLexer(new ANTLRFileStream(input));
>  >CommonTokenStream tokens = new CommonTokenStream(lexer);
>  >// prints 0
>  >System.out.println(tokens.size());
>  >
>  >So according to this there are no tokens, which would explain the
>  >blank debugger Input window. If the ANTLRWorks Interpreter runs
>  >the code correctly, why not the Debugger or unit tests?
> 
> Actually that's a bit deceptive :)
> 
> The stream starts out empty, and thus .size() returns 0.  It doesn't get 
> populated until the first time a token is requested.  So after calling 
> .nextToken() once then .size() should give you the true value.

Even after calling lexer.nextToken() the .size() still returns zero.

> Silly question, perhaps, but are you sure you're filling in the input 
> window properly when starting the debugger?  And actually stepping 
> through to the end?
> Generally, I find the debugger significantly more reliable than the 
> interpreter ever is...

I'm filling the input window properly, and a __Test___input.txt file is 
generated in the output folder which contains the entered input. I make 
sure to step through to the end, using either the Fast Forward button or 
single stepping. At one point this Grammar did work correctly in the 
debugger.

I hope we can figure out why this is apparently difficult in ANTLR. 
Thanks for your help.


More information about the antlr-interest mailing list