On 08/12/2009 05:45 PM, Nikolay Ognyanov wrote:
> Hi everybody,
>
> Please have a look at a toy grammar for language consisting of 2
> statements :
>
> grammar Ambiguous;
>
> expr
> : expr1
> | expr2
> ;
> expr1
> : PREFIX_1 expr2 SUFFIX
> ;
> expr2
> : PREFIX_2
> | PREFIX_2 SUFFIX
> ;
>
> PREFIX_1 : 'prefix_1';
> PREFIX_2 : 'prefix_2';
> SUFFIX : 'suffix';
> WS : (' ' | '\r' | '\n' | '\t')+ {$channel=HIDDEN;};
>
>
> Please do not advise how to fix it :) I know that but the question is why
> ANTLR considers rule for expr2 ambiguous? Here is a tool run:
Because at the time it is in expr2, it is ambiguous as to whether it
should match PREFIX_2 and exit, or match PREFIX_2 SUFFIX and then exit.
You only have 1 token of lookahead (by default). You might be able to
correct with syntactic predicates or a higher value of k, but your
grammar is not well defined because of the ambiguity.
--
Kevin J. Cummings
[email protected]
[email protected]
[email protected]
Registered Linux User #1232 (http://counter.li.org)
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---