Parsing C with missing typedefs

Bernt Kullbach <>
18 Apr 1999 02:00:36 -0400

          From comp.compilers

Related articles
Parsing C with missing typedefs (Bernt Kullbach) (1999-04-18)
Re: Parsing C with missing typedefs (1999-04-19)
Re: Parsing C with missing typedefs (1999-04-19)
| List of all articles for this month |

From: Bernt Kullbach <>
Newsgroups: comp.compilers
Date: 18 Apr 1999 02:00:36 -0400
Organization: Compilers Central
Keywords: C, errors, question, parse, comment

Hi there,

does anyone know how I can parse C when typedefs are missing.
You are eg. confronted with

typedef int INT;
INT i;

When the first line is missing from the source code you get in troubles.

Within my lex/yacc-based parser I used the ANSI-grammar from
Kernighan/Ritchie. Using this grammar the scanner has to decide
if an integer-like token is a typedef name or not. I implemented this
feature using a symbol table for typedef names.

How can I proceed when type definitions can be missing. The scanner
cannot rely on his symbol table any more.
I tried operating with a lookahead in the identifier rule. But this does

not seem to be powerful enough.

Thanks for any help,
Bernt Kullbach (
[Seems pretty hard, since typedef in effect invents new keywords. Perhaps
some of the general purpose error correction work might be useful, or you
could do something gross and ad-hoc like backup and do a trial reparse
pretending the undefined identifier is a type. -John]

Post a followup to this message

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