[antlr-interest] Trouble with ANTLR 3 grammar

Emond Papegaaij e.papegaaij at student.utwente.nl
Sat Jul 1 05:26:28 PDT 2006


On Friday 30 June 2006 20:51, Terence Parr wrote:
> On Jun 30, 2006, at 11:43 AM, Emond Papegaaij wrote:
> > I'm printing the tokens (for debugging) before parsing with a
> > simple while
> > loop. Maybe this is causing the problem? I've included the
> > Main.java that,
> > together with the grammar included in my first mail in this thread,
> > triggers
> > the problem.
>
> That should be ok; you can try tokens.toString() but that only prints
> the text by default.
>
> Hmm...so when you print that stuff, the channel shows 99 on the
> whitespace right before going to the parser?

The lexer does hit 'channel=99', but only after the token is already emitted. 
Printing the channel inside the loop in Main shows '0'. For every WS token 
mWS is called twice. It seems that on the first call the token is emitted, 
and on the second call the channel is set. I can't explain why. Here is some 
output with println statements added at the start of the method, at 
the 'channel=99' statement and at the 'emit' statement:

inWS
emit(11,1,9,0,9,9)
inWS
channel=99; line=1 char=9
inWS
emit(11,1,11,0,11,12)
inWS
channel=99; line=1 char=11


Best regards,
Emond Papegaaij


More information about the antlr-interest mailing list