[antlr-interest] HELP NEWBIE: How can I simplify Tree Parser grammar.

ghassempoory ghassempoory at ntlworld.com
Sun May 11 05:50:19 PDT 2003


I have a simple expression parser that generates an expression
tree. I have written a tree parser to walk this tree for further
processing. The tree parser looks a bit like :

expression:
       #(MUL expression expression)
    |  #(DIV expression expression)
    |  #(ADD expression expression)
    |  #(SUB expression expression)
    |  IDENTIFIER
    |  NUMBER
    ;

Well, this works fine.However I would like to simplify this by
doing soemthing like:

expression:
       #(opnode expression expression)
    |  IDENTIFIER
    |  NUMBER
    ;

opnode:
        MUL | DIV | ADD | SUB
    ;

ANTLR does not like this, it insists that the tree roots
should be specified directly.

Is there anyway that I could factor out the root nodes? 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list