[antlr-interest] A newbie's question

Michael Bedward michael.bedward at gmail.com
Tue Mar 17 18:58:03 PDT 2009


Hi,

First decide if you really need step 3 (the tree parser).  If you want
to parse some program / script and then perform evaluation multiple
times, or you want to work on the AST to optimize execution or make it
easier to do translation etc. then the answer is yes.  But if you just
want to parse a program / script and run it once then it's optional -
you could just embed actions in the parser grammar in step 2.

In my own apps I do more or less copy the parser grammar (minus
actions and AST rewrite rules) and use this as the basis for the tree
grammar.  If the grammar is not huge this is practical, but if it is,
or if there are multiple tree walking stages (ie. step 4, step 5 etc
each of which generates a new AST) then it can get tricky.

There was a recent discussion of this here...
http://www.antlr.org/pipermail/antlr-interest/2009-February/032799.html

Hope this helps
Michael


More information about the antlr-interest mailing list