help-bison
[Top][All Lists]
Advanced

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

RE: bison puts too many tokens in the semantic value


From: Richard Garand
Subject: RE: bison puts too many tokens in the semantic value
Date: Sat, 3 Mar 2001 17:10:08 -0600

I've added instructions in the flex file to print the semantic value of the
scanned token, and it is always right. The problem is in bison. I'll try
making a copy instead of using direct assignment. Thanks for the tip.

Richard Garand
address@hidden
ICQ: 12190132
"The original, complete, and unadulterated Descent! Play the game that
turned 3D action on its head and made it puke!" - CGW

> -----Original Message-----
> From: Hans Aberg [mailto:address@hidden
> Sent: Saturday, March 03, 2001 11:57 AM
> To: Richard Garand
> Cc: address@hidden
> Subject: Re: bison puts too many tokens in the semantic value
>
>
> At 08:46 -0600 2001/03/03, Richard Garand wrote:
> >I have a rule in a bison file(name:   '"' NAME '"', where name is
> >alphanumeric characters), but when I try to use $2 (when NAME="abc") it
> >gives me abc". Why does it add the " at the end, even if it's
> another token?
>
> Your example is a little too sparse with details for it to be possible to
> say exactly what happens. So here some suggestions:
>
> But $2 is the value that your lexical analyzer writes into yylval
> (assuming
> NAME is a terminal, i.e., a %token). So check that is written correctly.
> Flex writes a '\0' at the end of yytext until it starts looking for the
> next token, when the  correct character in the stream is written back
> again, as you can see by reading the code it writes. So you only have to
> make sure making an independent copy of it using say strcpy() under C. I
> use C++, and make an independent copy by the use of (in Flex)
>   yylval.text = std::string(yytext, yyleng);
>
> Funny things can also happen if one uses the wrong number n in the $n
> variable: If you use an n for which the yylval hasn't been set,
> you may end
> up with some remains from another variable.
>
>   Hans Aberg
>
>
>




reply via email to

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