0

Is there a way to "preprocess" C99-style digraphs to obtain a C file (or a .i preprocessed source) such that the resulting file does not contain any digraphs?

For instance, given the following source code:

%:define N 5

int main() <%
  int a<:N:> = <%2,1,0%>;
  char *s = "a<:b";
  return a<:4:>;
%>

Using GCC's preprocessor option (-E, plus -dD for good measure) is sufficient to get rid of the %: digraph (which gets evaluated and re-printed as #define in this example), but not the others.

Clang behaves in the same way, so it doesn't help much.

As far as I understand, simple regular expression substitutions would not work, since they would end up replacing occurrences inside strings.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
anol
  • 8,264
  • 3
  • 34
  • 78

1 Answers1

1

As far as I know, there is no standard tool which does this transformation. In particular, the preprocessor does not substitute digraphs, because (unlike trigraphs) digraphs are just ordinary tokens which happen to mean the same thing as other ordinary tokens.

It would be relatively straightforward to write such a processor using flex, starting with an existing flex definition for C.

rici
  • 234,347
  • 28
  • 237
  • 341