编译原理实验-递归子程序法

编译原理实验-递归子程序法

ID:28480458

大小:154.41 KB

页数:10页

时间:2018-12-10

编译原理实验-递归子程序法_第1页
编译原理实验-递归子程序法_第2页
编译原理实验-递归子程序法_第3页
编译原理实验-递归子程序法_第4页
编译原理实验-递归子程序法_第5页
资源描述:

《编译原理实验-递归子程序法》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、递归子程序法:#include"stdio.h"//include"stdlib.h"voiddisplay();charread();//读取字符函数voidwrite();charlookhead;voidE();voidT();voidG();voidS();voidF();voidmatch(charch);voiderror();//出错处理charstring[10];inttop;intmain(){display。;write();lookhead=read();E();puts(string);printf("为合法字符串!

2、nH);system("pause");return0;}voidE(){printf("E->TG");T();GO;}voidG(){if(lookhead=='+'){printf("G->+TG");match('+');G();}elseif(lookhead=='-'){printf("G->-TG");matedT();GO;}else{printf("G->sH);}voidT(){printf("T->FS");F();SO;voidS(){if(lookhead=='*'){printf("s->*FS

3、n");matchC**);F();SO;}elseif(lookhead=='/'){printf(HS->/FS");matchC/');}else{printf("S->e");}voidF()if(lookhead==,('){printf("F->(E)u);match('(');E();match(')');}elseif(lookhead=='i'){match('i');}elseerror();}voidmatch(charch){lookhead=read();}voidwrite(){charcha;top=0

4、;printf(H请输入待分析字符串:");do{scanf("%c",&cha);string[top]=cha;top++;}while(cha!='#');top=0;}charread(){charcha;cha=string[top];top++;returncha;}voiderror(){puts(string);printf("为非法字符串!H);system(,,pausen);exit⑼;voiddisplay)){printf("班级:10级计本一班");printf("学号:1004011026");pr

5、intf("姓名:王晓龙");LL(1)分析方法:charstring[10];intcount=0;intstep=0;charM[16][6];//include"stdio.h"include"stdlib.h"includensthng.h"charS,X,a;//S文法的开始符号,X当前栈顶符号的工作单元,a当前输入符号的T作单元//存放输入的句型//计数器//记录步骤//存放产生式intrecord;//记录当前找到的M中产生式的下标charstack[10];//栈inttop;charVt[9]="i+-*/(>";//终结

6、符号inti;voiderror));//出错函数voidinit();//初始化预测分析表intjudge(charx,chara);voidanalyse!);voidmain(){init();//初始化预测分析表inti;intmarkl=O;charch;top=-l;printf("清输入要分析的字符串:">;string[O]='#';i=l;do{scanf("%cn,&ch);string[i]=ch;i++;}while(ch!='#*);printf("步骤tt分析栈tt剩余字符串H);top++;stac

7、k[top]=string[OJ;count++;top++;stack[top]='E';step++;printf("%dtt",step);for(inti=0;i<=top;i++)printf("%c",stack[i]);printf("ttn);i=l;while(string[i]!='O*){printf("%c",string[i]};i++;}printfCXn");analyse));system("pasue");}voiderror。{printf("分析失败!");system("pause");ex

8、it(O);}voidinit()//初始化预测分析表-已经产生式右部反转过來{strcpy(M[O],"EiGT");Strcpy(M[l],E(G

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

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

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