help-bison
[Top][All Lists]
Advanced

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

Re: can i change a non-terminal type without using %union?


From: Philip Herron
Subject: Re: can i change a non-terminal type without using %union?
Date: Wed, 22 Jul 2009 03:36:10 +0100
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)

Hey
As the resons i showed in (1) and (2), I indicate that bison  treats
non-termimal as integers and it change NUMBER from double to int when it get
yylval from flex.
  Is that right?
  I know I can using %union to specify the type of non-terminals,can i fix
the problem without using the directive of %union?
  Thank you very much.
So am i right in saying your having problems when you do something like:

$$ = X

And maybe it not being the right type etc? In your flex lexer you have defined yystype this is ok but this means all types must be the same then that means each rule that returns in bison like $$=... and each lexical token that uses yylval is a double, which isn't great way of doing it. The whole %union thing isn't as daunting as you might think!

in your bison do

%union{
 int integer;
 double dbl;
 float flt;
}

Now get rid of the yystype and when you do yylval= bla
do yylval.integer= atoi() etc... and in your bison

%token<integer> INTEGER
... etc

And then for your rules if a rule returns a double:

%type<dbl> rulex

this should help alot more it makes things a little more tight :). I may have missed your question proper though.. its late here so let me know if this doesn't help!

--Phil
http://redbrain.co.uk




reply via email to

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