help-bison
[Top][All Lists]
Advanced

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

Re: I'm getting messages from Bison that aren't even listed on the inter


From: Philip Herron
Subject: Re: I'm getting messages from Bison that aren't even listed on the internet.
Date: Mon, 03 Aug 2009 03:54:03 +0100
User-agent: Thunderbird 2.0.0.22 (X11/20090608)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hey

I think i see the problem, try to split your grammar up more and make
more use of the lexer.. read-on

address@hidden wrote:
> Results from Google re Your search - gnu bison "$$ of `constant'
> has no declared type" - did not match any documents. That message
> (beginning "$$) is derived when processing the grammar file into
> Bison.
>
> The screen message is.. parse.y:98.43-44: $$ of `constant' has no
> declared type
>
> Line 98  in the grammar looks like... exp:  MAX '(' exp ',' exp ')'
> { $$ = (($3 > $5) ? $3 : $5 );}
>
> There are other complaints about line 98, which don't seem clear...
>
>
let look at this MAX rule so i take it you want it to look something like

MAX ( 5 , 3 )
and $$ = 5

But your grammar looks like exp : MAX ( exp, exp )

So your making more recursion in the end, your parameters to this rule
are equal to its $$ but that sort of loops on itself.

Like say you have the rule:

addme : IDENTIFIER '=' INTEGER '+' INTEGER
{ $$ = $3 + $5; }

You would %type<val> addme
etc.. but this means the grammar only cares that an expression always
looks like:

bla = 3 + 2
or bla = 55 + 71

Your 'exp' goes in on itself it would accept if it compiled.

MAX ( MIN ( OR ( ..... )))))))

As exp is a rule, although you have assigned %type<val> exp, which is
and int but it doesn't work that way. As yacc doesn't treat those
parameters to that rule as the current tokens in the %union. As the
union can be very different though out the run.

You should have something like in a LEX

[0-9]+  { yylval.val = atoi(yytext); return INTEGER; }

and your yacc

token<val> INTEGER

then

exp : MAX '(' INTEGER ',' INTEGER ')
       {
          $$ = ( ($3 > $5) ? $3 : $5 );
       }


I think should work fine.  Oh i just noticed you have %token<val> NUM
try sticking that in place of the exp as the parameters to those
functions.

- --Phil
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkp2UUoACgkQAhcOgIaQQ2HfHQCfZYhBUOyGi19CuyV0sMD9vbcF
T6gAn1GYWbTlUgfSlQUJdFimbCu0Cwpx
=f4W2
-----END PGP SIGNATURE-----





reply via email to

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