预览加载中,请您耐心等待几秒...
1/9
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/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