[antlr-interest] (no subject)
Imre András
iar73 at freemail.hu
Fri Oct 31 18:39:50 PDT 2008
Gerald Rosenberg <gerald at certiv.net> írta:
> At 04:36 PM 10/31/2008, =?ISO-8859-2?Q?Imre_Andr=E1s?= wrote:
>
> >--- unreachable.g --------------------
> >grammar unreachable;
> >
> >ID : ('a'..'z'|'A'..'Z')+ ;
>
> ....
>
> >sequence returns [String value]: 'SEQUENCE' WS* '{' WS*
> >e=rightValue {$value=$e.value;} (WS* ',' WS* e=rightValue {$value +=
> >$e.value;})* WS* '}' {return $value;};
>
> The unreacheable compile analysis-time error is likely due to the
> fact that ID will consume all alpha characters, leaving no way to
> match the literal 'SEQUENCE'.
>
> BTW, since you are skip()ing whitespace, you can remove the WS* from
> the parser rules with no affect.
>
> ady got rid of the unreachable error based on Terence's comments. However, you have a point that the ID and SEQUENCE are ambigous. Interpreting A ::= SEQUENCE{ SEQUENCE } gives a MismatchedTokenException, though parsing continues after a resync.
I put SEQUENCE : 'SEQUENCE' in the grammar, and modified the sequence rule to use it. Now it does not compile because of the ambiguity.
Now how can I explicitly tell that SEQUENCE is a keyword, and not a valid ID?
Thanks,
András
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081101/f9e38a2e/attachment.html
More information about the antlr-interest
mailing list