preprocessor algorithms (Paul Keddie)
Thu Feb 13 09:26:31 1992 GMT

          From comp.compilers

Related articles
preprocessor algorithms (1992-02-15)
| List of all articles for this month |

Newsgroups: comp.std.c,comp.compilers
From: (Paul Keddie)
Keywords: C, macros, question
Organization: British Telecom Research Labs
Date: Thu Feb 13 09:26:31 1992 GMT

Has anyone a good reference to the algorithms which a C preprocossor uses
for macro expansions? Especially in dealing with nested and parameterized

I'm writing a program that parses C code but needs to record information
generated at the preprocessor stage, hence I can't just run the code
through a standard preprocessor first. The sort of information I need to
collect is a list of what macros are defined, and where are they used.

The program I'm writing will probably use LEX and YACC and I'm hoping
that at the LEX stage I will be able to:
1. Record macro definitions.
2. Spot and record the use of any macro, but return to YACC the legal C code
      which the macro standards for, including dealing with any parameters.

Does this seem a good strategy? If so then what I need to find out is how
best to handle stage 2.

Software Maintenance Group, Software Technology Division, BT
Research Labs, Martlesham Heath, Ipswich, IP5 7RE, UK
Phone: +44 473 649154
Fax: +44 473 643019
[Doing a C preprocess and parse in a single pass in lex and yacc is difficult
for several reasons. Lex has no good way to handle include files, though
flex fixes that problem. Worse, the preprocessor needs to be able to handle
C expressions for #if, and yacc has no way to handle multiple parsers active
at once. There are band-aids for that, too, that have been discussed at
length here in the past. -John]

Post a followup to this message

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