[antlr-interest] help - Parser problem

Gavin Lambert antlr at mirality.co.nz
Sun Nov 30 23:30:50 PST 2008


At 18:56 1/12/2008, virg g wrote:
>If the command is
>TESTCMD CNT=2 VAL=TYPE:CNT
>
>It returs error "EarlyExitException" , if i change lexer rules i 
>get Mismatchtokenexception. But command is never successful. I 
>have figured out that If the literal contains any of these 
>keywords CNT, VAL, TYPE, RTEST parsing fails, that means it 
>igonres these tokens while parsing by parser eventhough these 
>tokens(eg CNT) is/are created by Lexer.
>How can i resolve this kind of problems. I cannot avoid having 
>these tokens in my command as the literal can be any of form. 
>Really i am stuck here.

Step 1: realise that using quoted literals in parser rules results 
in automatic creation of corresponding lexer rules with a funny 
name.  It's often clearer if you try to avoid doing this.

Step 2: realise that in ANTLR, the lexer runs to completion up 
front and outside of parser control.  So parser context has no 
influence on how things get tokenised.

Step 3: notice how your 'literal' rule doesn't mention any of the 
other literal tokens mentioned in step 1, so it's not surprising 
that it doesn't match them.

Step 4: realise that you can now fix it.

...

Step N: profit!  :)



More information about the antlr-interest mailing list