[antlr-interest] Doubt Regarding TreeWalker Error!!

mark twain himmy070 at gmail.com
Fri Aug 8 12:21:13 PDT 2008


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?
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.

So by this definition is it correct to say, above output is Parse Tree and
not AST as it has rules also?? I would be extremely thankful if you could
please explain or send me some link to understand the exact
difference illustrated with example

Actually i need to write to some grammar for my intern project within time
frame of  2 weeks and first step towards that project is to generate AST and
output  for all basic mathematical operations(kind of calculator as in your
example codes)

Cheers:)

On 8/8/08, Jim Idle <jimi at temporal-wave.com> wrote:
>
>  On Fri, 2008-08-08 at 11:20 -0400, mark twain wrote:
>
> Hi,
>
>
>
> I was trying to run one of the example code <simplecTreeParser> and when I
> execute the following command :
>
>
>
>  treePsr->program(treePsr);
>
>
>
> I am getting the following error :
>
> =================================
>
> ./input(1)  : error 10 : Unexpected node, at offset 0, near <missing
> <invalid>> : Missing <invalid>
> ./input(2)  : error 10 : Unexpected node, at offset 0, near <missing
> <invalid>> : Missing <invalid>
>
> =================================
>
>
>
> My input file is :
>
> int x;
>
> void bar(int x);
>
> int foo(int y, char d) {
>   int i;
>   for (i=0; i<3; i=i+1) {
>     x=3;
>     y=5;
>   }
> }
> =========================================
>
> I have not made any changes from example code and tried to run using C
> runtime library(antlr-3.1b2).
>
> Any pointers what I am missing.
>
>
> yes - The released version ;-). I fixed this issue a couple of days ago and
> the runtime fix is in the current tgz which is now just 3.1 and not 3.1bn,
> although it isn't officially released yet because the c# runtime still needs
> a day or twos more work. I may take advantage of this to fix a few things
> with debugging and so on.
>
> I think that there is a new snapshot of the antlr jars too - use those with
> the latest C runtime.
>
> Jim
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080808/cddac2fe/attachment.html 


More information about the antlr-interest mailing list