help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Give me an example please!!!


From: Javier Andres Mena Zapata
Subject: Re: Give me an example please!!!
Date: Thu, 6 Jun 2002 11:51:03 -0500 (COT)

Thank you, but I need to know how can I evaluate the expressions, that is,
what are the ACTIONs. I've thinking about it, but i'm not sure...

%union {
 int number;
 int operator;  /* 0 to sum, 1 to substract, and * to multiply */
}

%token <number> num
%token <operator> prim

%%
exp: prim '(' list_of_exp ')' { push_operator( $1 );
                                $$ = $3;
                                pop_operator(); }
   | number                   { $$ = $1; }

prim:
    '+' { $$ = 0; }
  | '-' { $$ = 1; }
  | '*' { $$ = 2; }

list_of_exp:
    exp             { $$ = $1; }
  | list_of_exp exp { $$ = evaluate_with_current_operator($1,$2); }
 %%

> In the Bison .y file your grammar might look like:
>
>
> Your YYSTYPE must be able to store both a number and the operator type. So
> you might use the %union feature (see Bison manual), one field of number
> type X, and then perhaps your operators will have type (C++ pseudo-code)
>     X (*)(const &list<X>)

I didn't understand this part (especially I don't know so much about
the STL from C++).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]