Re: Parsing C++ with lex++ and bison++ ?

Boris Burshteyn <bburshte@us.oracle.com>
Wed, 29 Jun 1994 00:43:26 GMT

          From comp.compilers

Related articles
Parsing C++ with lex++ and bison++ ? kumar@decster.uta.edu (1994-06-16)
Re: Parsing C++ with lex++ and bison++ ? ruiter@ruls41.leidenuniv.nl (1994-06-19)
Re: Parsing C++ with lex++ and bison++ ? bburshte@us.oracle.com (Boris Burshteyn) (1994-06-23)
Re: Parsing C++ with lex++ and bison++ ? aleung@netcom.com (1994-06-25)
Re: Parsing C++ with lex++ and bison++ ? bburshte@us.oracle.com (Boris Burshteyn) (1994-06-29)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Boris Burshteyn <bburshte@us.oracle.com>
Keywords: C++, parse, tools
Organization: Compilers Central
References: 94-06-117 94-06-187
Date: Wed, 29 Jun 1994 00:43:26 GMT

Allen Leung writes:
>...a guess why $-type with constructors aren't allowed: the semantic
>stack(at least in Bison) is implemented as an array of unions and
>C++ disallows constructors in components of a union.


Moderator writes:
>The problem is that the parse value stack is an array of unions, so that
>when you push and pop them stack C++ can't tell what type each is. ...


Of course, both Allen and John are right. Since C++ disallows constructors for
unions, there is no way to use them. But the union approach implies a naive
implementation of a parsing stack.


That is why my parser generator MUSKOX explicitly casts every attribute that
it encounters in an action to that attribute's type or class. The stack is
still allocated as a number of chunks of size M where


M=max{sizeof(attribute type) for all attributes}


By default attributes are copied using memcpy(). Also, there is an option
which forces a skeleton parser to use a copy-constructor instead of
memcpy(), so that user can define a copy-constructor of her own.


I have not implemented calling a constructor before passing an attribute
to a lexer yet, neither there are provisions for destructors when reducing
a stack. Though these features can be provided, I am just looking for a
convincing example where they are required.


Regards, Boris.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.