On 11 January 2012 00:39, UJWAL POTLURI <[email protected]> wrote:
> Can you please show me an example of how to do.
>
> On Tue, Jan 10, 2012 at 3:52 AM, Hans Aberg <[email protected]> wrote:
>
>>
>> On 10 Jan 2012, at 01:38, UJWAL POTLURI wrote:
>>
>> >     I am new to Bison. I am able to parse the grammar using Bison but I
>> am
>> > unable to figure out how to generate the parse tree. I would be grateful
>> if
>> > anyone could help me out in this.
>>
>> You'll have to build it in the grammar actions.
>>
>> Hans
>>
>>
>>
>
>
> --
> Ujwal Potluri,
> Masters student,
> Computer Science,
> University of Connecticut,
> Connecticut, USA.
> _______________________________________________
> [email protected] https://lists.gnu.org/mailman/listinfo/help-bison


The bison manual has some good basic examples if i recall. But take
the general idea of something like:

x = 1 + 2;

The DAG of this would be something like:

   =
 /   \
x     +
      /  \
     1   2

So you would have the grammar:

expr = identifier '=' expr
        | expr '+' expr
        ...
        | primary

So you could simply have the structure:

struct tree {
  type T;
  union {
    int x;
    char * s
    struct tree * t;
  } opa;
  union {
    int x;
  .....
  };
};

And you parse each thing in a simple way. Read on here
http://www.gnu.org/software/bison/manual/html_node/Infix-Calc.html#Infix-Calc
or read the dragon book and the Lex and Yacc o'reilly book is good.
Just make it in a way that makes things easy for you just think about
how the parser parsers things and you should get the idea.

--Phil

_______________________________________________
[email protected] https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to