%{ #include bool leave_docs = false; %} %x SINGLE_LINE %x MULTI_LINE %% "///"|"//!" { if (leave_docs) { ECHO; } else { BEGIN(SINGLE_LINE); } } "/**"|"/*!" { if (leave_docs) { ECHO; } else { BEGIN(MULTI_LINE); } } "//" { BEGIN(SINGLE_LINE); } . { ECHO; } \n { BEGIN(INITIAL); } . { } "/*" { BEGIN(MULTI_LINE); } "*/" { BEGIN(INITIAL); } . { } %% // single line comment /* * multi line comment */ /// single line doc 1 //! single line doc 2 /** * multi line doc 1 */ /*! * multi line doc 2 */ #include int main(int argc, char *argv[]) { if (argc > 1) { leave_docs = true; } yylex(); return EXIT_SUCCESS; }