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: Hans Aberg
Subject: Re: bison puts too many tokens in the semantic value
Date: Sat, 3 Mar 2001 18:56:48 +0100

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]