[antlr-interest] parse trees and syntax of parse trees

John D. Mitchell johnm-antlr at non.net
Thu Apr 22 08:49:56 PDT 2004


>>>>> "ronald" == ronald petty <ronald.petty at milliman.com> writes:
[...]

> That is sort of what I thought.  Lexer->Parser->(AST?)->TreeWalker

To be a bit more precise:

(A) Almost always exactly one:  Source characters -> Lexer -> Tokens

(B) One of either:

    Syntax-Directed Translation (SDT) case:

	Tokens -> Parser -> (direct) output   (i.e., .obj, .class, etc.)

    or, Intermediate Representation (IR) generation case:

	Tokens -> Parser -> AST (+ any auxillary data structures (e.g.,
	symbol table))

(C) Zero or more:

	AST -> TreeWalker/TreeTransformer -> AST

(D) One or more:

	AST -> TreeWalker -> output


> So when using the parser without any tree syntax that would still produce
> a AST correct?  If so, why have the manual intervention of the Tree
> syntax?  I believe I am confused on the seperation of the parser and
> trees.

Antlr can be configured to generate a parser which will automatically
construct a tree for you.  BUT! Such trees really suck because they are
basically stupid parse trees rather than abstract trees that have a form
that are good to work with.

One common trick is to turn on the automatic tree construction in the
parser as a whole but then selectively turn it off in individual (usually
more complex) rules and construct the trees manually at those points.

Check out the various larger example translators for lots of details about
how this works.

Have fun,
	John


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list