Chinaunix首页 | 论坛 | 博客
  • 博客访问: 295901
  • 博文数量: 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:57:47

  1. %option noyywrap

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

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

  6. %}

  7. %%

  8. ^("float")/([ ]|[\t]|[\n]) { translated("double"); }
  9. [ ]("float")/([ ]|[\t]|[\n]) { translated(" double"); }
  10. [\t]("float")/([ ]|[\t]|[\n]) { translated("    double"); }

  11. %%

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

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


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