Lex进阶实验
结合 实验:
用Lex工具进行词法分析,完成如下要求:
输入一个C/C++源文件,输出一个HTML文件,语法高亮显示C/C++源文件。
【实验步骤】
Compiler Bin Directory
C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO 10.0\VC\BIN
Compiler Bin Directory(2) C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO 10.0\COMMON7\IDE
Compiler Include Directory C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO 10.0\VC\INCLUDE
Compiler Include Directory(2) C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\INCLUDE
Compiler Library Directory C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO 10.0\VC\LIB
Compiler Library Directory(2) C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\LIB
Compiler Bin Directory(2) C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO 10.0\COMMON7\IDE
Compiler Include Directory C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO 10.0\VC\INCLUDE
Compiler Include Directory(2) C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\INCLUDE
Compiler Library Directory C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO 10.0\VC\LIB
Compiler Library Directory(2) C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC98\LIB
- Keys int|double|float|char|void|#include|else|case|struct|return
- thekey {Keys}/[ \t]+
- keyif if/ .∗
- keyswitch switch/ .∗
- str \".*\"
- comments1 \/\/.*
- comments2 \/\*(.|\n)*\*\/
- \n {fputs("<br/>",yyout);}
【实验结果】
读入input.c的C文件如下:
![](https://img-my.csdn.net/uploads/201207/18/1342621400_3384.png)
运行程序后,会生成output.html的文件,用浏览器打开:
![](https://img-my.csdn.net/uploads/201207/18/1342621432_6300.png)