Re: about syntax trees

"grable" <grable0@gmail.com>
21 Mar 2007 00:04:39 -0400

          From comp.compilers

Related articles
about syntax trees chinluchinawa@yahoo.co.uk (chinlu chinawa) (2007-03-19)
Re: about syntax trees grable0@gmail.com (grable) (2007-03-21)
Re: about syntax trees chinluchinawa@yahoo.co.uk (Chinlu) (2007-03-23)
Re: about syntax trees leppoc@gmail.com (leppoc@gmail.com) (2007-03-23)
Re: about syntax trees DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-03-26)
| List of all articles for this month |
From: "grable" <grable0@gmail.com>
Newsgroups: comp.compilers
Date: 21 Mar 2007 00:04:39 -0400
Organization: Compilers Central
References: 07-03-073
Keywords: parse
Posted-Date: 21 Mar 2007 00:04:39 EDT

On Mar 19, 8:40 pm, chinlu chinawa <chinluchin...@yahoo.co.uk> 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))


Post a followup to this message

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