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

John D. Mitchell johnm-antlr at non.net
Wed Apr 21 16:18:01 PDT 2004


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

> If I wanted to make a parse tree for a language so I can transform it
> into another tree, is there any use in creating a non tree grammar for
> that language?

Do you want strictly a "parse tree" or do you want an abstract syntax tree?
I.e., do you want a tree which strictly and precisely encodes the source or
do you want something more abstract?


> I am slightly confused about when to use the different types of grammars
> (token or tree).  At first I was under the impression you make the token
> grammar then convert to the tree.  If that is correct why would you do
> that?  If it is wrong what is the normal way to do it.  I looked at some
> examples and they seem to either be completly seperate or a mixture of
> both whichs leads me to my middle ground of not understanding.

Think of the following as a pipeline...

You write a lexer grammar so that Antlr will generate a lexer to consume
individual characters from the source file and output tokens.

You write a parser grammar so that Antlr will generate a (token) parser to
consume the tokens from the lexer and then output an "abstract syntax
tree" (AST).

You write zero or more tree grammars so that Antlr will generate a tree
walker/transformer to consume an AST and output an AST.

You write a tree grammar so that Antlr will generate a tree walker to
consume the final AST and output whatever your final output needs to be.

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