[antlr-interest] Re: HELP NEWBIE: How can I simplify Tree Parser grammar.
lgcraymer
lgc at mail1.jpl.nasa.gov
Sun May 11 20:48:10 PDT 2003
Unfortunately, the only way to do this with the current
implementation is to change the type on the root nodes (previous
tree walking or parsing phase). Not recommended--I'd suggest living
with what you have.
--Loring
--- In antlr-interest at yahoogroups.com, "ghassempoory"
<ghassempoory at n...> wrote:
> 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