Hi,

I'm new to Bison. I'm writing an interpreter for a lightweight C-like
language using flex and bison. My language has to support the *two*
types *int* and *float* used by the identifiers.

My question is, do I have to write separate rules for both types in my
.y file, where each set of rules is dedicated for a given type, or do
I have to handle the differentiation between those types in the
grammatical actions associated with a unified set of rules for these
two types?

Here is an example of the grammar, I coded for bison:

expr: CONSTINT                      { $<ival>$ = $<ival>1; }
    | CONSTFLOAT                   { $<fval>$ = $<fval>1; }
    | IDENTIFIER                   { $<ival>$ = getvalue($<id>1); }
    | expr ADD expr                { $<ival>$ = $<ival>1 + $<ival>3; }
    | expr SUB expr                { $<ival>$ = $<ival>1 - $<ival>3; }
;

If I opt for the second case, I would, for example, modify the
function getvalue to distinguish between the two types given the
identifier's name, stored in id.

Any ideas guys?

BR,
Ilyes Gouta.


_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to