编译原理上机源代码lr语法分析器

编译原理上机源代码lr语法分析器

ID:11410865

大小:27.67 KB

页数:17页

时间:2018-07-11

编译原理上机源代码lr语法分析器_第1页
编译原理上机源代码lr语法分析器_第2页
编译原理上机源代码lr语法分析器_第3页
编译原理上机源代码lr语法分析器_第4页
编译原理上机源代码lr语法分析器_第5页
资源描述:

《编译原理上机源代码lr语法分析器》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、输入:3+4*6输出:27(当然中间包括LR(1)语法分析过程程序提供主要为了给大家提供一些方便,你懂得。。。呵呵如有问题,QQ:718561468来自:大连理工大学软件学院#includeusingnamespacestd;#include#include#include#includestringAnalyzeChart[16][11]={//LR文法的分析表"s5","e1","e1","s4","e2","e1","1","2","3","e1","e1","e3","s6","e1","e3"

2、,"e2","acc","error","error","error","s7","e1","e6","r2","s8","e6","r2","r2","error","error","error","r2","s9","e6","r4","r4","e6","r4","r4","error","error","error","r4","r4","s5","e1","e1","s4","e2","e1","10","2","3","e1","e1","e5","r6","r6","e3","r6","r6","error","error","error","r6","r6","s5"

3、,"e1","e1","s4","e2","e1","error","11","3","e1","e1","s5","e1","e1","s4","e2","e1","error","12","3","e1","e1","s5","e1","e1","s4","e2","e1","error","error","13","e1","e1","s5","e1","e1","s4","e1","e1","error","error","14","e1","e1","e3","s6","e1","e3","s15","r3","error","error","error","s9","e1

4、","e6","r1","s8","e6","r1","r1","error","error","error","r1","s9","e6","r7","s8","e6","r7","r7","error","error","error","r7","s9","e6","r3","r3","e6","r3","r3","error","error","error","r3","r3","e6","r8","r8","e6","r8","r8","error","error","error","r8","r8","e6","r5","r5","e6","r5","r5","error"

5、,"error","error","r5","r5",};stackdigit;queuedigit1;queueinputid;char*FinalSymbol[6]={"i","+","*","(",")","#"//终结符};char*UnfinalSymbol[5]={"E","E'","T","T'","F"//非终结符};stackufstack;//状态栈voidinitialize(){ufstack.push('0');inputid.push(0);}char*keyword[6]={"for","if","the

6、n","else","while","do"};intflag1=-1,flag2=-1;typedefstructsign{intline;inttoken;chartemp[10];inti;};voidreset(sign&s){s.i=0;memset(s.temp,'$',10);s.token=-1;}boolis_key_word(sign&s){inti,r;for(i=0;i<6;i++){r=memcmp(s.temp,keyword[i],s.i);if(r==0){s.token=i+1;returntrue;break;}}returnfalse;}bool

7、is_id(sign&s){inti;boolb=false;if((s.temp[0]>='a'&&s.temp[0]<='z')

8、(s.temp[0]>='A'&&s.temp[0]<='Z'))b=true;elsereturnb;for(i=1;i='a'&&s.temp[i]<='z')

9、(s.temp[i]>='A'&&s.temp[i]<='Z')

10、(s.temp[i]>=

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。