help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C preprocessor


From: Giacinto Cifelli
Subject: C preprocessor
Date: Thu, 13 Aug 2020 07:49:52 +0200

Hi all,

I am wondering if it is possible to interpret a c-preprocessor (the second
preprocessor, not the one expanding trigrams and removing "\\\n") or an m4
grammar through bison, and in case if it has already been done.
I think  this kind of tool does not produce a type-2 Chomsky grammar,
rather a type-1 or even type-0.
Any idea how to build something like an AST from it?

The purpose would be to use in a text editor, to know how to format for
example a block between #if/#endif (according to the condition, for example
could be greyed out if false),

or whether all blocks are closed (see for example this (simplified) macro
from systemd):
    #    define _SD_BEGIN_DECLARATIONS                              \
            extern "C" {                                            \
            struct _sd_useless_struct_to_allow_trailing_semicolon_
    #endif

 or to colorize a macro, although this latter would require post-processing
its expansion with a normal C grammar, and pick one of the tokens (the last
for example) as representative of the adequate color.

Thank you,
Giacinto


reply via email to

[Prev in Thread] Current Thread [Next in Thread]