1、/*实验 1 词法分析源码已经通过 VS2010 调试,亲测可用,有打开文件操作(在工程文件夹里建一个 program.txt,输入程序串即可) 。也可从键盘直接输入源码,后面的语法分析也能用的上,欢迎使用。*/#include#include #includeusing namespace std;void KeyFunction();void ReadTxt();void main() int choose;coutchoose;if(choose=1)cout=ab=getchar();if(b=|b=) di+=b;b=getchar();cout)/*识别和=*/ di+=b;b=g
2、etchar();if(b=) di+=b;b=getchar();cout=ab=out.get();if(b=|b=) di+=b;b=out.get();cout)/*识别和=*/ di+=b;b=out.get();if(b=) di+=b;b=out.get();cout“运算符“dendl;for(j=0;j=i;j+)dj=0;i=0;else cout“运算符“dendl;for(j=0;j=i;j+)dj=0;i=0;else if(b=:)/*识别:=*/ di+=b;b=out.get();if(b=) di+=b;b=out.get();cout“符号“dendl;else cout“error line!“endl;for(j=0;j=i;j+)dj=0;i=0;else if(b=*|b=+|b=-|b=/|b=)/*识别运算符*/ cout“运算符“bendl;b=out.get();else if(b=(|b=)|b=,|b=;|b=.)/*识别分隔符 */ cout“分隔符“bendl;b=out.get();else cout“xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx“endl;cout“error line!“endl;b=out.get();out.close();