Re: Parsing C with missing typedefs (Dwight VandenBerghe)
19 Apr 1999 14:48:06 -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: (Dwight VandenBerghe)
Newsgroups: comp.compilers
Date: 19 Apr 1999 14:48:06 -0400
Organization: Compilers Central
References: 99-04-050
Keywords: parse, C

On 18 Apr 1999 02:00:36 -0400, Bernt Kullbach
<> wrote:
>does anyone know how I can parse C when typedefs are missing.

Sure. John's second suggestion is the way to go, but you need to do
it at full strength - in other words, trying to look ahead with simple
techniques won't work. Construct a second full parser from the ground
up just to do the lookahead. Have it available to call as a
subroutine when needed, then call it when your normal parsing fails.
Design its grammar to recognize every valid declaration that could
follow a typedef name (and don't forget to handle casts as well).
Make sure that it caches the lexical tokens that it eats from the
input stream, so that when it returns with a Yes or No (that tells you
whether the unknown identifier was a typedef name or not), you can go
back to parsing with your regular parser and it will retrieve the
already-seen tokens from the input cache. Mark any new typedef names
found in the symbol table as typedefs and make sure that they are
recognized as such from that point in the source onward, or this won't
work - it will only work to recognize one new typedef name at a time.

You'll make things easier on yourself if you use a modern parser
generator that supports re-entrant parsers.


Post a followup to this message

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