编译原理实验二语法分析器LL(1)实现 下载本文

内容发布更新时间 : 2024/6/8 4:28:22星期一 下面是文章的全部内容请认真阅读。

else {

printf(\ exit(0); } }

else if(ch=='E') {

printf(\进入E\\n\

if(tokenlist[op].code==10||tokenlist[op].code==20||tokenlist[op].code==1) {

push(&s,'R');

printf(\将R压入栈\\n\ push(&s,'T'); } }

else if(ch=='R') {

printf(\进入R\\n\

if(tokenlist[op].code==3||tokenlist[op].code==4) {

push(&s,'R'); push(&s,'T');

printf(\将T压入栈\\n\ push(&s,'+'); }

if(tokenlist[op].code==2||tokenlist[op].code==0) { } }

else if(ch=='T') {

printf(\进入T\\n\

if(tokenlist[op].code==10||tokenlist[op].code==20||tokenlist[op].code==1) {

push(&s,'Y'); push(&s,'F'); } }

else if(ch=='Y') {

printf(\进入Y\\n\

if(tokenlist[op].code==5||tokenlist[op].code==6) {

push(&s,'Y'); push(&s,'F'); push(&s,'*'); } else

if(tokenlist[op].code==3||tokenlist[op].code==2||tokenlist[op].code==0||tokenlist[op].code==4) {

} }

else if(ch=='F') {

printf(\进入F\\n\

if(tokenlist[op].code==10||tokenlist[op].code==20) {

push(&s,10); }

if(tokenlist[op].code==1) {

push(&s,')'); push(&s,'E'); push(&s,'('); } } else {

printf(\ exit(0); } }while(flag); }

程序运行结果:(截屏)

输入:((Aa+Bb)*(88.2/3))#

注:如需运行请将文件放置F盘,并命名为:输出:

2.txt