[antlr-interest] Problem with grammar

Wojciech Tomasz Cichon wtcichon at googlemail.com
Sat Mar 19 05:18:35 PDT 2011


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


More information about the antlr-interest mailing list