help-bison
[Top][All Lists]
Advanced

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

Multitype support in bison


From: Ilyes Gouta
Subject: Multitype support in bison
Date: Sat, 13 Oct 2007 01:10:00 +0200

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.




reply via email to

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