%option stack noyywrap %{ #include %} %x str %x ccmt %x cxxcmt %% \" { putchar ('"'); yy_push_state (str); } { \\\" fputs (yytext, stdout); \" { putchar ('"'); yy_pop_state (); } . fputs (yytext, stdout); } "/*" { fputs (yytext, stdout); yy_push_state (ccmt); } { "*/" { fputs ("*/", stdout); yy_pop_state (); } . fputs (yytext, stdout); } "//" { fputs ("/*", stdout); yy_push_state (cxxcmt); } { \n { puts (" */"); yy_pop_state (); } . fputs (yytext, stdout); } . fputs (yytext, stdout); %% int main (void) { yyin = stdin; yylex (); return 0; }