[antlr-interest] Must all grammar rules be implemented for tree parsers?

Rob Greene robgreene at gmail.com
Mon Dec 5 20:25:29 PST 2005


>From the example "An Example Tree Transformation" at
http://www.antlr.org/doc/sor.html#_bb1, I think I can do some basic
tree optimization before getting to the point of generating code for
my compiler.

1) From my experimenting, I cannot just pick nodes that are
optimizable, can I? From what I'm seeing, I think I need to build
enough of the language into the tree parser to get to the optimizable
parts. As a simple example, numeric constants that are operated on
together can be computed by the compiler instead of the resulting code
(ie, "a = 24 * 60" can be replaced with "a = 1440"). Am I correct in
this? I cannot just write a rule for the "*" in that example. I need
to write the rule for the "=" and anything else preceding it?

2) Is there a reference of optimizations that are listed on some web
site (or in the ANTLR docs that I somehow haven't found)? The only
ones I've thought of are numeric or string constants being used in an
expression.

Thanks!
-Rob


More information about the antlr-interest mailing list