Re old post: newbie questions about AST

"Floris 'Tamama' van Gog" <>
23 Mar 2000 03:27:41 -0500

          From comp.compilers

Related articles
Re old post: newbie questions about AST (Floris 'Tamama' van Gog) (2000-03-23)
Re: Re old post: newbie questions about AST (2000-03-23)
| List of all articles for this month |

From: "Floris 'Tamama' van Gog" <>
Newsgroups: comp.compilers
Date: 23 Mar 2000 03:27:41 -0500
Organization: Casema Internet
Keywords: AST, parse, design

See old post below

I was thinking of implementing a procedure call in an AST like this:

int function(int arg1,int arg2,int arg3);

                                        / \
                                push 0
                              / \
                      push arg3
                    / \
            push arg2
          / \
        0 arg1

Where arg1 to arg3 can be expressions with subtree's (x+y) etc.
It seems that this way of doing things seems to be great for DAG's.

This in comparison to:

            / | \
        arg1 arg2 arg3

Where each arg is a seperate syntax tree. (Or you would have make each
tree reference to common nodes in other trees, nasty..)

Ok, i have no idea how to really make an AST (i'm having some probs
creating some nice structures that are both easy to use, and aren't too
bulky (each node very big))

Or am i seeing AST's completely wrong here and is the entire program one
big happy AST? That would result in nodes that do nothing but denote
that left/right nodes are something to do, and disregard any possible
values that come out of that.

I dont see how conditional jumps fit in an AST either :-)

Enlighten me please,


From: Felix Mish <>
Date: 5 Oct 1998 20:48:38 -0400
Organization: Compilers Central

Hello everyone, I am new to ASTs. Could anyone tell me how to describe
the following in AST:

1. Procedures such as:
void Function(int a,int b)


2. while(<expression>)

Thank you in advance.


You need to construct a data structure that will hold all function
calls and their corresponding stacks. Pascal/C/C++ will have a tree
of stacks as the AST for procedure calls. Each node in a tree will
contain a stack of all variables defined within the function. If a
variable outside the scope of the function is refered, then we look at
the parent node 's stack and so on. if in the while loop, you are
defining variables, then its like a nested function call. A *while*
will be a node that has an expression evvaluation subtree and on
evaluation that will lead to loop/end-of-loop .


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.