[antlr-interest] ast rewrite rule beginner question...

Pady Srinivasan padysrini at hotmail.com
Thu Dec 25 18:47:11 PST 2008



I am reading terence's book and am in "tree construction" chapter...but i
am not sure whether i found an example for a rule as the one below and how
to write the rewrite rule...

expression
    :   conditionalOrExpression (assignmentOperator expression)?
    ;

I wrote the rewrite rule as...

expression
    :   conditionalOrExpression (assignmentOperator expression)?
       --> ^(assignmentOperator? conditionalOrExpression expression? )
    ;

I get an error about the "?" after assignmentOperator in the rewrite rule.
Not sure what is the right format ? Or should i use a imaginary node for the
root like...

expression
    :   conditionalOrExpression (assignmentOperator expression)?
       --> ^(OPER conditionalOrExpression assignmentOperator? expression? )
    ;



Thx

-- pady



More information about the antlr-interest mailing list