如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
跟大家分享一下:这个必须从文件读入语法#include<cstdio>#include<iostream>#include<cstdlib>#include<fstream>#include<string>#include<cmath>usingnamespacestd;structtoken//token结构体{intcode;intnum;token*next;};token*token_head,*token_tail;//token队列structnumber//number结构体{intnum;intvalue;number*next;};number*number_head,*number_tail;//number队列structstr//string结构体{intnum;stringword;str*next;};str*string_head,*string_tail;//string队列structivan//表达式结构体{charleft;stringright;intlen;};ivancss[20];//20个表达式structpank//action表结构体{charsr;intstate;};pankaction[46][18];//action表intgo_to[46][11];//go_to表structike//分析栈结构体,双链{ike*pre;intnum;intword;ike*next;};ike*stack_head,*stack_tail;//分析栈首尾指针voidscan();//按字符读取源文件intjudge(charch);//判断输入字符的类型voidout1(charch);//写入token.txtvoidout2(charch,stringword);//写入number.txtvoidout3(charch,stringword);//写入string.txtvoidinput1(token*temp);//插入结点到队列tokenvoidinput2(number*temp);//插入结点到队列numbervoidinput3(str*temp);//插入结点到队列stringvoidoutput();//输出三个队列的内容voidoutfile();//输出三个队列的内容到相应文件中voidyufa_initialize();//初始化语法分析数据结构intyufa_main(inta);//语法分析主体部分intID1(inta);//给输入字符编号,转化成action表列编号stringID10(inti);//给输入字符反编号intID2(charch);//给非终结状态编号,转化成go_to表列编号intID20(charch);//给非终结状态编号charID21(intj);//给非终结状态反编号voidadd(ike*temp);//给ike分析栈链表增加一个结点voiddel();//给ike分析栈链表删除一个结点FILE*fp;//文件intwordcount;//标志符计数intnumcount;//整型常数计数interr;//标志词法分析结果正确或错误intnl;//读取行数voidmain(){token_head=newtoken;token_head->next=NULL;token_tail=newtoken;token_tail->next=NULL;number_head=newnumber;number_head->next=NULL;number_tail=newnumber;number_tail->next=NULL;string_head=newstr;string_head->next=NULL;string_tail=newstr;string_tail->next=NULL;//初始化三个队列的首尾指针wordcount=0;//初始化字符计数器numcount=0;//初始化常数计数器err=0;//初始化词法分析错误标志nl=1;//初始化读取行数scan();if(err==0){charm;cout&