[Top][All Lists]

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

Re: quick bison Q

From: David Durham
Subject: Re: quick bison Q
Date: Mon, 09 Dec 2002 10:26:37 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826

Paul Eggert wrote:

Date: Fri, 06 Dec 2002 09:29:19 -0600
From: David Durham <address@hidden>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826

I was wondering why

%union foo

doesn't work any more?  It doesn't like 'foo'

The Bison reader was redone recently, and my guess is that we didn't
know about this undocumented feature.  Also, POSIX does not require
support for this feature.  Instead of using "%union foo {...}", you
are supposed to do something like this:

   union foo { int ival;};
   #define YYSTYPE union foo
ahh.. I'll do it that way

the reason I need to name it is to be able to declare it as a friend
of a C++ class.

Perhaps we should add this feature back to Bison, but I'd like to know
exactly what is needed.
Yeah.. I was surprised that mandrake is still packaging 1.35.. I suppose because they've had problems using 1.5/7 with compiling some things.. might want to ask the bison packagers for mandrake: address@hidden

In C, the only thing that can appear between the "union" and the "{"
is an optional identifier (also white space and comments, of course).
Is the same true for C++?
I just checked the C++ spec, and the grammar itself shows union to have the exact syntax as a class. However as far as I know, there is no meaning for inheritance of unions (which is really the only specifier that can come after the ident).

However C++ does allow union to be followed by some template keyword stuff and some allows idents with '::' between them. I really don't think that bison should have to worry about what they mean. It could just find what's between the union keyword and the {, remove all the whitespace from that sequence of chars and define that as the character sequence of the typename for the union. If bison places that everywhere in the C code where the typename of the union is needed then when a C++ compiler compiles it it should, I think, work fine.

On the otherhand, you could check what bison 1.35 allowed and go with that. I think it just allowed a simple ident after the union.

I have a language-lawyer question for you, since I don't use C++
myself.  In C++, what exactly can appear between the "union" and the
"{"?  Is it OK for Bison to restrict it to be a valid C identifier?
Here is the grammar for a valid C identifier:

 identifier = letter (letter | digit)*

 digit = [0-9]
 letter = [_a-zA-Z] | "\u" x x x x | "\U" x x x x x x x x | idl
 x = [0-9a-fA-F]
 idl = <implementation-defined letter>

A backslash-newline can be inserted between any two characters, but I
don't think Bison should have to worry about that.

Those "implementation-defined letters" worry me a bit, though, since
there's no easy way for Bison to discover whether a letter is allowed
by the implementation.

From looking at the grammar C++ idents are exactly the same as C idents. And the \-newline stuff I believe would be handed by the preprocessor and not the C/C++ parser itself. And if something works in C it is supposed to work in C++ (perhaps with compiler warnings, but no errors)

I'm not sure what is meant by implementation-defined letter? Is that like a non-US-english character? Or is it something that can be defined by the user at bison-time?

reply via email to

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