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: Sun, 4 Mar 2001 01:01:47 +0100

At 17:10 -0600 2001/03/03, Richard Garand wrote:
>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.

No, the problem isn't in Bison.

What you do is that in the rule
  foo: '"' NAME '"' { s; }
when you get the $2 value, you hand over the yytext pointer (which points
into the buffer that the Flex scanner uses), which is then temporarily \0
terminated, and prints out nicely. After that you get the \" from the Flex
scanner, so the latter puts back the \" (read the code that the Flex
scanner writes!), and then hands over that position.

After that the action "s;" is executed, and so the non-copied $2 is NAME
plus the ", followed by the temporary \0 the Flex scanner puts in (as
yytext is just into the buffer that the Flex scanner uses). That is, if the
Flex scanner does not refill the buffer between reading the NAME and the "
...


  Hans Aberg





reply via email to

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