Re: Re: Recognition of typedefs in C ?

James H.Grosbach <>
26 Jan 2001 16:57:52 -0500

          From comp.compilers

Related articles
Recognition of typedefs in C ? (David Pereira) (2001-01-18)
Re: Recognition of typedefs in C ? (2001-01-19)
Re: Re: Recognition of typedefs in C ? (James H.Grosbach) (2001-01-26)
| List of all articles for this month |

From: James H.Grosbach <>
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

James Grosbach
Principal Compiler Engineer
Microchip Technology

Post a followup to this message

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