help-bison
[Top][All Lists]
Advanced

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

Re: How to read an understand the bison report file ?


From: Akim Demaille
Subject: Re: How to read an understand the bison report file ?
Date: Thu, 28 Jun 2012 09:09:11 +0200

Le 27 juin 2012 à 13:26, Timothy Madden a écrit :

> On 06/27/2012 09:44 AM, Akim Demaille wrote:
> [...]
>> 
>> Either you need to completely change the way you handle the
>> spaces/comments, or you have to use GLR, as Hans suggested.
> 
> I would hate to find that I have to push all whitespace/comments into the 
> content (semantic value) of the lexer tokens, so the grammar does not get to 
> see it.

Why would you hate that?  The grammar will be much simpler,
and the whole thing would certainly be much more efficient.

Saving these whitespaces in the scanner is not hard, so
you could keep all the ws+c stored somewhere, ready to be
returned with the next token.

Now you have to decide where to store that pre-token ws+c.
There are two places: the semantic value, or the location.
I would probably go to the semantic value.

Then again, where would you store it in the semantic value?
Either use a %union of members that all have a dedicated place
for it, but that would certainly be tedious.

Or cheat.

Instead of

%union
{
  int ival;
  char *sval;
  …;
};

do something like

struct semantic_value
{
  char *wsc; // Whitespace and comments
  union
  {
    int ival;
    char *sval;
    …
  };
};
#define YYSTYPE struct semantic_value

then you can use $$ as usual, but $<wsc>$ or $<wsc>1 will
give you the spaces.

> On the other hand, I could not get GLR with C++ yet…

I have it working, but it's based on horrible hacks.  And
I really mean horrible.  If PHP in itself does not need it,
I would avoid it.




reply via email to

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