help-bison
[Top][All Lists]
Advanced

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

Question for types in bison


From: david sander
Subject: Question for types in bison
Date: Wed, 28 Jan 2009 23:41:53 +0100
User-agent: Thunderbird 2.0.0.19 (X11/20090105)

Hello i have a problem with types of non-terminals in bison

The testing of the types doesn't run as it have to do in the following example


expr:
expr '+' expr {if ($<intValue>1 && $<intValue>3) {$<intValue>$= $<intValue>1+$<intValue>3 ;} /* beides int*/

else if($<floatValue>1 && $<floatValue>3) {$<floatValue>$= $<floatValue>1+$<floatValue>3 ;} /* beides float*/

else if($<intValue>1 && $<floatValue>3) {$<floatValue>$= $<intValue>1+$<floatValue>3 ;} /* eins int eins float*/

else if($<floatValue>1 && $<intValue>3) {$<floatValue>$= $<floatValue>1+$<intValue>3 ;} /* eins foat eins int*/

                    else yyerror("unmatching types!");
                   }


Only if both Types of expr are from intValue $$ should become intValue, but the first if-clause always match also by 4.5 + 3.4 .

%union {
   double floatValue;
int intValue; }

So where is my Error. I thought that $<intValue>1 tests if the first expr ist an int or not, is this correct ?
If not how can I check if $1 is an int or an float ?


Thanks David





reply via email to

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