Search code examples
cgccbisonflex-lexer

Can we use GCC to process translation phases 1..5 for C project


I am trying to use ANSI C Lex and Yacc grammar to parse my C project. In the description of that grammar, it requires

It is assumed that translation phases 1..5 have already been completed, including preprocessing and _Pragma processing. The Lex rule for string literals will perform concatenation (translation phase 6). Transliteration of universal character names (\uHHHH or \UHHHHHHHH) must have been done by either the preprocessor or a replacement for the input() macro used by Lex (or the YY_INPUT function used by Flex) to read characters.

How can I use GCC to process translation phases 1..5?


Solution

  • How can I use GCC to process translation phases 1..5?

    The closest GCC offers is its -E option, which causes it to stop "after the preprocessing stage" and emit the result to the standard output.

    GCC's preprocessing phase lines up at least approximately with translation stage 4 in C's abstract translation model, but I cannot attest to whether the output of gcc -E matches exactly what one should expect for the result of stages 1-4. If so, then that result differs from what you ask only when the source character set differs from the execution character set and the source contains at least one character that is mapped differently by those sets.