[antlr-interest] help - Parser problem

virg g 06virg at gmail.com
Tue Dec 2 21:28:56 PST 2008


On Mon, Dec 1, 2008 at 1:00 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:

> 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.


ok. Is there anyway i can mention the commands and its paramters without
mentioning them in the quotes?


>
> 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.


The literal rule is combination of "OR" of Number, ALPHA and STRING. So for
the command " TESTCMD CNT=2 VAL=TYPE:CNT" where for VAL  paramters CNT will
match ALPHA lexer rule right? as it works if it is "TEST". Otherwise i have
to add expilcitely all the quoted values to "literal" rule like this. sorry
if understanding is wrong.

literal    : (NUMBER|ALPHA|STRING |TESTCMD|'CNT'|'VAL'|'TYPE')



> Step 4: realise that you can now fix it.
>
> ...
>
> Step N: profit!  :)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081203/f8380a03/attachment.html 


More information about the antlr-interest mailing list