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的例子
  1. %{
  2.         int chars = 0;
  3.         int words = 0;
  4.         int lines = 0;
  5. %}
  6. %%
  7. [a-zA-Z]+ { words++;chars +=strlen(yytext); }
  8. \n                { chars++; lines++; }
  9. .                { chars++; }
  10. %%
  11. main(int argc,char **argv)
  12. {
  13.         yylex();
  14.         printf("%8d%8d%8d\n",lines,words,chars);
  15. }
复制代码

作者: 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