Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 在 flex/lex 中获取 c 样式注释的问题
我正在使用 flex 编写一个词法分析器,我怎样才能使它避免看起来像这样的注释:
/* COMMENTS */
这有点复杂。这是我找到的解决方案:
<INITIAL>{ "/*" BEGIN(IN_COMMENT); } <IN_COMMENT>{ "*/" BEGIN(INITIAL); [^*\n]+ // eat comment in chunks "*" // eat the lone star \n yylineno++; } { return COMMENT; }
“明显”的解决方案,如下所示:
"/*".*"*/" { return COMMENT; }
会匹配太多。