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

ronald.petty at milliman.com ronald.petty at milliman.com
Thu Apr 22 08:25:16 PDT 2004


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

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.

Thanks John.

Ron



"John D. Mitchell" <johnm-antlr at non.net> 
04/21/2004 06:18 PM
Please respond to
antlr-interest at yahoogroups.com


To
antlr-interest at yahoogroups.com
cc

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






>>>>> "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



 




**************************************************************************************
This communication is intended solely for the addressee and is
confidential. If you are not the intended recipient, any disclosure, 
copying, distribution or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. Unless indicated
to the contrary: it does not constitute professional advice or 
opinions upon which reliance may be made by the addressee or any
other party, and it should be considered to be a work in progress.
**************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20040422/7052592a/attachment.html


More information about the antlr-interest mailing list