[antlr-interest] Would somebody help me clarify the difference between AST, Tree Grammars, and Parse Trees?

Terence Parr parrt at cs.usfca.edu
Sun Oct 14 17:56:08 PDT 2007


Well, you can look at stuff like:

http://www.antlr.org/article/1100569809276/use.tree.grammars.tml

http://www.jguru.com/faq/view.jsp?EID=818959

but in essense. a grammar parses tokens (and generates trees).  a  
lexer parses char, a tree grammar parses trees. :)  Only diff is the  
input stream really.

Ter
On Oct 14, 2007, at 3:57 PM, ANTLR Mailing List wrote:

>
>
> I need a good example/explanation between the difference between  
> tree grammars, ASTs and Parse Trees.
>
> I see that grammars don't have to be tree grammars to output ASTs.
>
> This is very confusing to me...
>
>
> For a simple grammar to test:
>
> // Begin Grammar
> grammar TestGrammar;
>
>
> options {
>     output = AST;
>     k = 10;
> }
>
> tokens {
>     STAT;
>     SEMI = ';';
> }
>
> program    :    statement *;
>
> statement
>     :    expression SEMI;
>
> expression
>     :    INT;
>
> INT    :    ( '0'..'9' ) +;
> // End Grammar
>
> When removing "output = AST", I see no difference in the output  
> generated by ANTLRWorks.
>
> When putting "tree " in front of "grammar TestGrammar", it fails  
> and generates a NullPointerException.
>
> Anybody have an explanation?



More information about the antlr-interest mailing list