码迷,mamicode.com
首页 > 其他好文 > 详细

软件构造—— 实验二 lex词法分析

时间:2020-01-17 20:42:57      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:拷贝   词法分析   std   src   文件   double   字符串   print   alt   

实验题目:

拷贝一个C文件,将其中的关键字int替换成float。

代码:

 1 %{
 2 %}
 3 %%
 4 //表示如果是在双引号(")中(即为字符串),则照常打印,编译时请删除此注
 5 \".*\"  {printf("%s",yytext);}
 6 [^ \t\n]+ {printf("%s",yytext);}
 7 //表示如果遇到float,且附加模式是后面跟有空白符,则将float替换为double,编译时请删除此注释
 8 int/[ \t]+ {printf("float");}
 9 \n|. {printf("%s",yytext);}
10 %%
11 #pragma comment(lib,"y1.txt")
12 int main(void)
13 {
14     yyin=stdin;
15     return yylex();
16 }

截图:

技术图片

软件构造—— 实验二 lex词法分析

标签:拷贝   词法分析   std   src   文件   double   字符串   print   alt   

原文地址:https://www.cnblogs.com/smartisn/p/12207384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!