[antlr-interest] Doubt Regarding TreeWalker Error!!

Jim Idle jimi at temporal-wave.com
Fri Aug 8 13:20:17 PDT 2008


On Fri, 2008-08-08 at 15:21 -0400, mark twain wrote:
> Hi Jim,
>  
> I just tried to incorporate some of your minor code changes and I
> tried using following statement from one of your code snippet:
> "   printf("Tree : %s\n",
> SimpleCAST.tree->toStringTree(SimpleCAST.tree)->chars);"
> ================================
> and gets the following output:
> Tree : (VAR_DEF char c) (VAR_DEF int x) (FUNC_DECL (FUNC_HDR void bar
> (ARG_DEF int x))) (FUNC_DEF (FUNC_HDR int foo (ARG_DEF int y) (ARG_DEF
> char d)) (BLOCK (VAR_DEF int i) (for (= i 0) (< i 3) (= i (+ i 1))
> (BLOCK (= x 3) (= y 5)))))
>  
> I have a very silly question to ask, so please dont mind :-)
> Is it the output Tree, that I am getting above is Parse tree or AST? 


It is the AST - the tree built by the rewrite rules. The parse tree is
rarely useful.


> Actually , I gone though lot of online documentation but still couldnt
> convince myself the exact difference between parse tree and AST. Some
> article says that Parse tree is a syntactic structure of string where
> interior nodes are non-terminals of grammar and leaf nodes are
> terminals whereas AST has no rule nodes and has only token nodes.

The parse tree is how the parser traversed the input. The AST is what
you build to represent the input for further processing. You can see the
parse tree if you use the JAva version of the example with ANTLRWorks in
debug mode.

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080808/ca10aed3/attachment.html 


More information about the antlr-interest mailing list