[antlr-interest] Problem with grammar
Matt Fowles
matt.fowles at gmail.com
Sat Mar 19 06:12:14 PDT 2011
Wojciech~
Try pulling out the common left factor from your term expression:
term : factor (('*'|'/'|'*') term)?;
Matt
On Sat, Mar 19, 2011 at 12:18 PM, Wojciech Tomasz Cichon
<wtcichon at googlemail.com> wrote:
> i’m struggling with this grammar for a few days now, and nothing really working,
> so i started from beginning and i have :
> grammar myGrammar;
>
> options {
> language = Java;
> k=1;
> }
>
> rule: term ;
>
> factor : '-'? NUMBER
> ;
>
> term : factor '*' term
> | factor '/' term
> | factor '%' term
> | factor;
>
>
>
> NUMBER : '0'..'9'+
> ;
> WS : ( ' '
> | '\t'
> | '\r'
> | '\n'
> ) {$channel=HIDDEN;}
> ;
>
>
> and i got errors:
> warning(200): /ANTLR_TEST/myGrammar.g:13:7: Decision can match input such as "'-'" using multiple alternatives: 1, 2, 3, 4
> As a result, alternative(s) 2,3,4 were disabled for that input
> |---> term : factor '*' term
>
> warning(200): /ANTLR_TEST/myGrammar.g:13:7: Decision can match input such as "NUMBER" using multiple alternatives: 1, 2, 3, 4
> As a result, alternative(s) 2,3,4 were disabled for that input
> |---> term : factor '*' term
>
> error(201): /ANTLR_TEST/myGrammar.g:13:7: The following alternatives can never be matched: 2,3,4
> |---> term : factor '*' term
>
> can anyone tell me what i’m doing wrong
> regards
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
More information about the antlr-interest
mailing list