[antlr-interest] rule rewrite

David Holroyd dave at badgers-in-foil.co.uk
Mon Apr 2 02:21:31 PDT 2007


On Mon, Apr 02, 2007 at 11:15:09AM +0300, F?rat K???K wrote:
> this is simple sample inline calculator grammar:
> 
> start : operation ((PLUS^ | MINUS^) operation)* ;
> operation : NUMBER ((ASTERISK^ | SLASH^) NUMBER)* ;
> 
> but i need:
> 
> start : operation ((ADDITION^ | SUBTRACTION^) operation)*;
> 
> how can i rewrite this rules without changing rule.

Do you mean like this,

  start : operation (additionOperator^ operation)* ;
  additionOperator : PLUS -> ADDITION | MINUS -> SUBTRACTION ;

(untested)


-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list