Chinaunix
标题:
lex文件编译出错
[打印本页]
作者:
chinesefys
时间:
2012-09-28 18:39
标题:
lex文件编译出错
%{
int wordCount = 0;
%}
words [A-za-z/_/'/./"]
%%
{words} { wordCount++;}
%%
void main()
{
yylex();
printf(" No of words:%d\n", wordCount);
}
int yywrap()
{
return 1;
}
root@ubuntu:~/eclipseworkspace/flexyacc# flex frame.l
frame.l:6: 不能识别的规则
frame.l:6: 不能识别的规则
frame.l:6: 不能识别的规则
作者:
goingstudy
时间:
2012-09-28 18:39
给你个flex的例子
%{
int chars = 0;
int words = 0;
int lines = 0;
%}
%%
[a-zA-Z]+ { words++;chars +=strlen(yytext); }
\n { chars++; lines++; }
. { chars++; }
%%
main(int argc,char **argv)
{
yylex();
printf("%8d%8d%8d\n",lines,words,chars);
}
复制代码
作者:
goingstudy
时间:
2012-09-28 19:54
推荐一本书,flex & bison
作者:
chinesefys
时间:
2012-09-28 20:16
回复
3#
goingstudy
非常感谢!
PS:其实我的程序是对的,我编译环境没配置好。。。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2