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
<[email protected]> 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
>

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.

Reply via email to