You need to construct the correct LL tree form of the rules. Always copy
from a pre-written grammar in the examples or read the book and you will not
struggle so much:
factor
: addexp (('+'|'-')* addexp
;
addexp
: mulexp (('*'|'/') mulexp)*
;
mulexp
: '-' mulexp
| atom
;
atom
: NUMBER
| '(' factor ')'
;
Jim
> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Wojciech Tomasz Cichon
> Sent: Saturday, March 19, 2011 5:19 AM
> To: [email protected]
> Subject: [antlr-interest] Problem with grammar
>
> 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.