/* Remove comments from C or C++ program */ /*============= 1. The definitions section ================*/ %{ #include #include #include %} %s CCOMM CPPCOMM %% /*============= 2. The rules (regular expressions) section ======*/ "//" { BEGIN(CPPCOMM); } .|\n { ECHO; } . { } "\n" { BEGIN(INITIAL); printf("\n"); } "/*" { BEGIN(CCOMM); } .|\n { } "*/" { BEGIN(INITIAL); } %% /*============= The user programs section ===================*/ int main() { yylex(); return 0; } int yywrap() { return 1; } /* Stop at end of file */