您所在位置: 网站首页 / 编译原理实验-递归子程序法.doc / 文档详情
编译原理实验-递归子程序法.doc 立即下载
2024-02-29
约4.2千字
约9页
0
48KB
举报 版权申诉
预览加载中,请您耐心等待几秒...

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

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

预览

免费试读已结束,剩余 4 页请下载文档后查看

9 金币

下载文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

递归子程序法:#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("为合法字符串!\n");system("pause");return0;}voidE(){printf("E->TG\n");T();G();}voidG(){if(lookhead=='+'){printf("G->+TG\n");match('+');T();G();}elseif(lookhead=='-'){printf("G->-TG\n");match('-');T();G();}else{printf("G->ε\n");}}voidT(){printf("T->FS\n");F();S();}voidS(){if(lookhead=='*'){printf("s->*FS\n");match('*');F();S();}elseif(lookhead=='/'){printf("S->/FS\n");match('/');}else{printf("S->ε\n");}}voidF(){if(lookhead=='('){printf("F->(E)\n");match('(');E();match(')');}elseif(lookhead=='i'){match('i');}elseerror();}voidmatch(charch){lookhead=read();}voidwrite(){charcha;top=0;printf("请输入待分析字符串:\n");do{scanf("%c",&cha);string[top]=cha;top++;}while(cha!='#');top=0;}charread(){charcha;cha=string[top];top++;returncha;}voiderror(){puts(string);printf("为非法字符串!\n");system("pause");exit(0);}voiddisplay(){printf("班级:10级计本一班\n");printf("学号:1004011026\n");printf("姓名:王晓龙\n");}LL(1)分析方法:#include"stdio.h"#include"stdlib.h"#include"string.h"charS,X,a;//S文法的开始符号,X当前栈顶符号的工作单元,a当前输入符号的工作单元charstring[10];//存放输入的句型intcount=0;//计数器intstep=0;//记录步骤charM[16][6];//存放产生式intrecord;//记录当前找到的M中产生式的下标charstack[10];//栈inttop;charVt[9]="i+-*/()";//终结符号inti;voiderror();//出错函数voidinit();//初始化预测分析表intjudge(charx,chara);voidanalyse();voidmain(){init();//初始化预测分析表inti;intmark1=0;charch;top=-1;printf("请输入要分析的字符串:\n");string[0]='#';i=1;do{scanf("%c",&ch);string[i]=ch;i++;}while(ch!='#');printf("步骤\t\t分析栈\t\t剩余字符串\n");top++;stack[top]=string[0];count++;top++;stack[top]='E';step++;printf("%d\t\t",step);for(inti=0;i<=top;i++)printf("%c",stack[i]);printf("\t\t");i=1;while(string[i]!='\0'){printf("%c",string[i]);i++;}printf("\n");analyse();system("pasue");}voiderror(){printf("分析失败!\n");system("pause");exit(0);}voidinit()//初始化预测分析表-已经产生式右部反转过来{strcpy(M
查看更多
单篇购买
VIP会员(1亿+VIP文档免费下)

扫码即表示接受《下载须知》

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

文档大小:48KB

限时特价:扫码查看

• 请登录后再进行扫码购买
• 使用微信/支付宝扫码注册及付费下载,详阅 用户协议 隐私政策
• 如已在其他页面进行付款,请刷新当前页面重试
• 付费购买成功后,此文档可永久免费下载
全场最划算
12个月
199.0
¥360.0
限时特惠
3个月
69.9
¥90.0
新人专享
1个月
19.9
¥30.0
24个月
398.0
¥720.0
6个月会员
139.9
¥180.0

6亿VIP文档任选,共次下载特权。

已优惠

微信/支付宝扫码完成支付,可开具发票

VIP尽享专属权益

VIP文档免费下载

赠送VIP文档免费下载次数

阅读免打扰

去除文档详情页间广告

专属身份标识

尊贵的VIP专属身份标识

高级客服

一对一高级客服服务

多端互通

电脑端/手机端权益通用