Re: about syntax trees
- From: "grable" <grable0@xxxxxxxxx>
- Date: 21 Mar 2007 00:04:39 -0400
On Mar 19, 8:40 pm, chinlu chinawa <chinluchin...@xxxxxxxxxxx> wrote:
Hello,
I'm relatively new to parsing. I've managed to code a
recursive-descent ll(1) parser in c (thus, a
stack/table based one). My question is about syntax
trees.
If I trace each accepting operation with a printf,
this is what I get for the expression: a+b*c
accept on: a
accept on: +
accept on: b
accept on: *
accept on: c
However I can see ast's being more like this all over
the place:
+
/|\
b | a
*
c
But I cannot think of a way you get exactly this, any
pointers or advises? thanks so much.
You could use something like this:
struct node {
int tag;
char* value;
struct node* left;
struct node* right;
}
struct node a = { ID, "a", NULL,NULL };
struct node b = { ID, "b", NULL,NULL };
struct node b = { ID, "c", NULL,NULL };
struct node op2 = { BINOP, "*", &b, &c };
struct node op1 = { BINOP, "+", &a, &op2 };
Resulting in a list like this:
(+ a (* b c))
.
- Follow-Ups:
- Re: about syntax trees
- From: Chinlu
- Re: about syntax trees
- References:
- about syntax trees
- From: chinlu chinawa
- about syntax trees
- Prev by Date: Re: flex and bison in vc++6 or vc++8
- Next by Date: Re: flex and bison in vc++6 or vc++8
- Previous by thread: about syntax trees
- Next by thread: Re: about syntax trees
- Index(es):
Relevant Pages
|
|