Parsing C Preprocessor files
Bram Stolk
bram at nospam.sara.nl
Wed Jun 23 08:49:47 EDT 2004
On Wed, 23 Jun 2004 08:32:08 -0400
Peter Hansen <peter at engcorp.com> wrote:
> Bram Stolk wrote:
>
> > What could I use to parse CPP macros in Python?
> > I tried the Parnassus Vaults, and python lib docs, but could not
> > find a suitable module.
>
> Does it really need to be in Python? There are probably
> dozens of free and adequate macro preprocessors out there
> already.
I want to trigger Python actions for certain nodes or states in the
parse tree. I want to traverse this tree, an be able to make
intelligent actions. For this, I want to use python.
> (You might also want to clarify what you mean by "parse"
> in this case... do you mean actually running the whole
> preprocessor over an input file and expanding all macros,
> or do you mean something else?)
Roughly speaking, I want to be able to identify sections that are
guarded with #ifdef FOO
Because conditionals can be nested, you would have to count the
ifs/endifs, and additionally, the conditional values may depend on other
preprocessor command, e.g. values may have been defined in included
files.
If I can traverse the #if/#endif tree in Python, a preprocessor file
becomes much more managable.
Bram
> -Peter
--
------------------------------------------------------------------------------
Bram Stolk, VR Engineer.
SARA Academic Computing Services Amsterdam, PO Box 94613, 1090 GP AMSTERDAM
email: bram at nospam.sara.nl Phone +31-20-5923059 Fax +31-20-6683167
"Software is math. Math is not patentable."
OR
"Software is literature. Literature is not patentable." -- slashdot comment
------------------------------------------------------------------------------
More information about the Python-list
mailing list