[antlr-interest] Ambiguity in grammar

Wojciech Tomasz Cichon wtcichon at googlemail.com
Sun Mar 20 21:26:53 PDT 2011


i have in my grammar rules:

stmt :
| ident '=' lexp SEMI  -> ^(SET ident lexp);


factor  : 
      '-'?  (NUMBER |ident )^
        ....
       ;

and
lexp : term (SIMOP^  lexp)?;
term  : factor (OP^  term)?;

OP :  '*' | '/' | '%';
SIMOP : '+' | '-';

and i tried it on different inputs
and for
ID = –5; , ID = 5+3; etc it works, and it build correct tree
bur if i’ll try 
ID = 5-3;
i get error: 
mismatched input '-' expecting SEMI

i’m using options:
options {
  language = Java;
  output = AST;
    k  = 3;
}

can anyone tell me what i should fix?
regards


More information about the antlr-interest mailing list