flex 关于不良品格的正则表达式问题
我是 Flex 正则表达式的新手,我不明白为什么它一直表现出不好的性格。我想知道是否“?!”存在于flex正则表达式中。如果不是,如何更换为正确的?
这是我的代码
%option noyywrap
%{
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
%}
/* ------------------- Rules space -------------------- */
%%
^aa(a|b)*$ {printf("Token1:%s\n" ,yytext);}
a{3}(a|b)*$ {printf("Token2:%s\n" ,yytext);}
a{2}(a|b)*$ {printf("Token3:%s\n" ,yytext);}
^(?:(a|b){2})+$ {printf("Token4:%s\n" ,yytext);}
^b*(ab*ab*)*$ {printf("Token5:%s\n" ,yytext);}
^(?:.{5})*$ {printf("Token6:%s\n" ,yytext);}
\b((?!aaa)\w)+\b {printf("Token7:%s\n" ,yytext);} // line 19 error appear here
.|\n {} // default rule (always include to match all other strings)
%%
/* ----------------- User code space ------------------ */
main()
{
yylex();
return;
}
I am new to the flex regular expression and I don't why it keep showing the bad character. I am wondering if the "?!" is exist in flex regular expression. If not, how to replace it with correct one?
Here is my code
%option noyywrap
%{
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
%}
/* ------------------- Rules space -------------------- */
%%
^aa(a|b)*$ {printf("Token1:%s\n" ,yytext);}
a{3}(a|b)*$ {printf("Token2:%s\n" ,yytext);}
a{2}(a|b)*$ {printf("Token3:%s\n" ,yytext);}
^(?:(a|b){2})+$ {printf("Token4:%s\n" ,yytext);}
^b*(ab*ab*)*$ {printf("Token5:%s\n" ,yytext);}
^(?:.{5})*$ {printf("Token6:%s\n" ,yytext);}
\b((?!aaa)\w)+\b {printf("Token7:%s\n" ,yytext);} // line 19 error appear here
.|\n {} // default rule (always include to match all other strings)
%%
/* ----------------- User code space ------------------ */
main()
{
yylex();
return;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论