Re: about syntax trees



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



Relevant Pages

  • Re: about syntax trees
    ... My question is about syntax ... struct node* left; ... a parse-tree got stuck again. ... I've uploaded the parser I've written, ...
    (comp.compilers)
  • about syntax trees
    ... recursive-descent llparser in c (thus, ... My question is about syntax ... trees. ...
    (comp.compilers)
  • Re: simplebinary tree
    ... You should look up AVR trees and red/black trees. ... typedef struct node { ... void inorder(sn *root) ... parent = x = NULL; ...
    (comp.lang.c)
  • Re: Non-Binary Trees
    ... >My assignment is to create a non-binary tree of arbitrary form, ... Example code to demonstrate non-binary trees has been ...
    (comp.programming)