3 ms·
Yes, the real reason C preprocessor syntax can't be described by a context-free grammar is that parsing and execution are interleaved. This requires the parser
by yorwba 9y ago
Yes, the real reason C preprocessor syntax can't be described by a context-free grammar is that parsing and execution are interleaved. This requires the parser to carry the set of current macro definitions for each parsing decisions, which implies non-context-freeness.
However, see [0] for a way to parse C with preprocessor #ifdefs (but after expanding #includes and #defines).
[0] "SuperC : Parsing All of C by Taming the Preprocessor" http://cs.nyu.edu/rgrimm/papers/pldi12.pdf http://cs.nyu.edu/rgrimm/papers/pldi12.pdf