T
Thomas Stegen
I have written a code generator. To be more specific it is a
code generator generator. As in a generator that generates
code generators. If you run the generator on its own source
code you get a code generator generator code generator. If you
run it on some other non-generator code you get a code generator
generator generator. Watch your bracketisation in all that. The
idea is to generate code which generate code which looks exactly
like the input to the the generator.
#include <stdio.h>
int main(void)
{
int c;
printf("#include <stdio.h>\n"
"\n"
"int main(void)\n"
"{\n"
"puts(\"");
while((c = getchar()) != EOF)
{
switch(c)
{
case '"':
printf("\\\"");
break;
case '\\':
printf("\\\\");
break;
case '\n':
printf("\\n\\\n");
break;
default:
putchar(c);
}
}
printf("\");\n"
"return 0;\n"
"}\n");
return 0;
}
code generator generator. As in a generator that generates
code generators. If you run the generator on its own source
code you get a code generator generator code generator. If you
run it on some other non-generator code you get a code generator
generator generator. Watch your bracketisation in all that. The
idea is to generate code which generate code which looks exactly
like the input to the the generator.
#include <stdio.h>
int main(void)
{
int c;
printf("#include <stdio.h>\n"
"\n"
"int main(void)\n"
"{\n"
"puts(\"");
while((c = getchar()) != EOF)
{
switch(c)
{
case '"':
printf("\\\"");
break;
case '\\':
printf("\\\\");
break;
case '\n':
printf("\\n\\\n");
break;
default:
putchar(c);
}
}
printf("\");\n"
"return 0;\n"
"}\n");
return 0;
}