[antlr-interest] Lexer rule with alternatives (Newbie question)
John B. Brodie
jbb at acm.org
Sat Nov 22 08:23:58 PST 2008
> Hello,
Greetings!
> why such grammar doesn't work properly:
> ---------------------------------------------------------------------------
>----------- expr :
> operand ((oper) operand)*
^^^^^^
I assume you mean the lexer rule OPER here?
> ;
> //Correct operands
> operand :
> INT
> ;
> OPER: ('+'|'-'|'*'|'/')
> ;
> INT :
> ('0'..'9')+
> ;
> ---------------------------------------------------------------------------
>-----------
>
> > t+1
^^^
your grammar does specify anything for how to handle the character 't'
>
> line 0:3 mismatched input '+' expecting EOF
>
> But if I replace the Lexer rule by Parser rule:
>
> oper: ('+'|'-'|'*'|'/');
>
> All work as it should. Why I should't use Lexer rule with alternatives ?
>
works for me with the following changes: (1) changed reference to oper to be
OPER in the rule expr, and (2) changed the test input to be "1+1"
i am using ANTLR v3.1 from 12 August 2008.
my test source grammar is this:
//-----cut here-----
> Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/27413b7a/attachment.html
More information about the antlr-interest
mailing list