Chinaunix首页 | 论坛 | 博客
  • 博客访问: 295570
  • 博文数量: 32
  • 博客积分: 665
  • 博客等级: 上士
  • 技术积分: 370
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-25 11:20
文章分类

全部博文(32)

文章存档

2023年(1)

2021年(1)

2020年(2)

2018年(3)

2014年(1)

2013年(2)

2012年(9)

2011年(9)

2010年(2)

2009年(2)

分类: C/C++

2012-02-23 21:53:25

  1. %option noyywrap

  2. %{
  3. #include <stdio.h>

  4. void showhelp(char* argv[]);
  5. void translated(const char* t);

  6. %}

  7. %%

  8. (([\t]+)|([ ]+))+ { translated(" "); }

  9. %%

  10. void showhelp(char* argv[])
  11. {
  12.   printf("Usage %s [input_filename] [output_filename]\n",argv[0]);
  13. }

  14. void translated(const char* t)
  15. {
  16.   fprintf(yyout,"%s",t);
  17. }


  18. int main(int argc,char* argv[])
  19. {
  20.   FILE* inputfile;
  21.   FILE* outputfile;
  22.   
  23.   if(argc != 3)
  24.     {
  25.      showhelp(argv);
  26.      return 0;
  27.     }
  28.   inputfile = fopen(argv[1],"r");
  29.   outputfile = fopen(argv[2],"w");
  30.   
  31.   if(inputfile && outputfile)
  32.     {
  33.      yyin = inputfile;
  34.      yyout = outputfile;
  35.      while(yylex());
  36.     }
  37.   else
  38.     {
  39.      printf("open file failed.\n");
  40.     }
  41.   return 0;
  42. }
阅读(1373) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~