[antlr-interest] Grammar refuses to compile (Simple ANTLR gotcha)
David Holroyd
dave at badgers-in-foil.co.uk
Tue Apr 24 06:31:00 PDT 2007
On Tue, Apr 24, 2007 at 04:40:51PM +0400, Ilia Kantor wrote:
> This grammar doesn't compile (ambiguitiy)
>
> I want "rule_call" to match "#a.b.c" from arbitrary text
>
> Could you please explain what's the reason of error I have here and how to fix it ?
>
> warning(200): My.g:8:24: Decision can match input such as "DOT WORD" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> warning(200): My.g:8:24: Decision can match input such as "MINUS GT WORD" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
>
>
> -----------------------------------------
>
> document:
> (text | rule_call)+;
>
> rule_call:
> GET_SCOPE_VALUE WORD rule_long_def_part+;
>
> rule_long_def_part
> :
> (MINUS GT WORD) => MINUS GT WORD |
> (DOT WORD) => DOT WORD;
>
>
> text:
> DOT | MINUS | WORD | WS| GT | SPECIAL_CHAR ;
I'd try adding,
((rule_long_def_part)=> rule_long_def_part)+
to make ANTLR match that content 'now', rather than exiting rule_call
and matching the tokens with text+ in the document rule. I guess you
don't need the predicates in rule_long_def_part itself?
[I didn't test that though.]
dave
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list