As far as I can understand
default: comment.replace(i, 0, "\\");
makes
case '\\': comment.replace(i, 0, "\\"); break;
useless.
Edit to add another comment :
Please activate all warnings on your code on one hand and on the generated code on the other hand. I think that :
void comment(int line, struct machine_state *m, const char *comment) {\n\
return;\n\
fprintf(stderr, \"%d %s\", line, comment);\n\
}\n\
shoud eventually warn you about unreachable code.