%{ /* remove C comments */ /* replace each comment with a single blank */ extern int fileno(FILE *); /* avoid gcc warning */ %} %x String Char Comment CPPComment %% \" /* "String" */ ECHO; BEGIN( String); \' /* 'Char' */ ECHO; BEGIN( Char); "/*" /* comment */ BEGIN( Comment); "//" /* C++ comment */ BEGIN( CPPComment); .|\n /* everything else */ ECHO; { \\. /* escape sequence */ ECHO; [^"] /* not "quote" */ ECHO; \" /* end of "String" */ ECHO; BEGIN( INITIAL); } { \\. /* escape sequence */ ECHO; [^'] /* not 'quote' */ ECHO; \' /* end of 'Char' */ ECHO; BEGIN( INITIAL); } { [^*]* /* not a '*' */ "*"+[^/] /* '*'s not followed by '/' */ "*"+"/" /* end of Comment */ putchar( ' '); BEGIN(INITIAL); } { .* /* to end of line */ \n ECHO; BEGIN( INITIAL); } %% void (*jj_junk)(int,char *) = yyunput; /* avoid gcc warnings */ int (*jj2_junk)(void) = input; int main( void) { yylex(); return 0; }