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: Recognition of typedefs in C ? apiron@ulb.ac.be (Anthony PIRON) (2001-01-19) |
Re: Recognition of typedefs in C ? Joachim.Pimiskern@de.bosch.com (Joachim Pimiskern) (2001-01-19) |
Re: Re: Recognition of typedefs in C ? james.grosbach@microchip.com (James H.Grosbach) (2001-01-26) |
Re: Recognition of typedefs in C ? jos@and.nl (Jos A. Horsmeier) (2001-01-26) |
From: | "David Pereira" <davidpereira@home.com> |
Newsgroups: | comp.compilers |
Date: | 18 Jan 2001 01:13:21 -0500 |
Organization: | Excite@Home - The Leader in Broadband http://home.com/faster |
Keywords: | C, types, parse, question |
Posted-Date: | 18 Jan 2001 01:13:21 EST |
Hi,
I am writing a C compiler and am at the parser stage. I have run
into a bit of a problem. I need to enable the lexer to distinguish
typedef names from ordinary identifiers. At first glance, it seemed
that building a table of typedef names was enough - the lexer would
consult this table and return TYPENAME if the name was found in this
table, otherwise IDENTIFIER. However, this is inadequate since
*context* matters. How can this context be discerned ?
The following piece of code demonstrates the inadequacies of a simple
typename table:
typedef int x; /* parser enters 'x' into the typename table */
x blah; /* lexer consults typename table and returns TYPENAME for
'x'. GOOD !!! */
int main ()
{
int x; /* lexer consults typename table and returns TYPENAME for x.
BAD !!! */
return 0;
}
Any ideas ??
DP.
[This is by far the ugliest part of parsing C. See the archives, it's
come up before. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.