Related articles |
---|
Recognition of typedefs in C ? davidpereira@home.com (David Pereira) (2001-01-18) |
Re: Recognition of typedefs in C ? henry@spsystems.net (2001-01-19) |
Re: Re: Recognition of typedefs in C ? james.grosbach@microchip.com (James H.Grosbach) (2001-01-26) |
From: | James H.Grosbach <james.grosbach@microchip.com> |
Newsgroups: | comp.compilers |
Date: | 26 Jan 2001 16:57:52 -0500 |
Organization: | Microchip Technology |
References: | 01-01-096 01-01-122 |
Keywords: | C, parse |
Posted-Date: | 26 Jan 2001 16:57:52 EST |
On Friday 19 January 2001 21:25, you wrote:
> >typedef int x; /* parser enters 'x' into the typename table */
> >...
> >int main ()
> >{
> > int x; /* lexer consults typename table and returns TYPENAME for x.
> >BAD !!! */
>
> Rather than trying to return IDENTIFIER for x, it suffices to accept
> either IDENTIFIER or TYPENAME for the name being declared. This does
> require some rearrangement of the grammar to ensure that the TYPENAME is
> not taken as part of the type specification, but it *can* be done -- I did
> it in an experimental parser.
This is the approach taken by the Roskind grammar (see the FAQ for
sources if you don't already have a copy) and it works quite
well. There's no getting around the fact that typedefs are a right
pain, but they can be done and keep things relatively clean in this
fashion.
--
James Grosbach
Principal Compiler Engineer
Microchip Technology
Return to the
comp.compilers page.
Search the
comp.compilers archives again.