资源简介
用c语言实现的语法语义分析程序 实现了四元式得生成功能齐全

代码片段和文件信息
#include
#include
#include
#include
#include
struct stake1
{ char *s[15];
int top;
} chstake;/*运算元素栈*/
struct stake2
{ char ch[20];
int sjb[20];
int top;
} ysstake;/*运算符号栈*/
struct lgstake1
{ char ch[10];
int top;
}logfh;/*逻辑运算符号栈*/
struct lgstake2
{ int ysbh[10];
int top;
}logys;/*逻辑运算元素*/
struct syshi/*四元式队列*/
{ char *s[4];
int bhao;
struct syshi *next;
}yshead*ystail;/*头节点和尾指针*/
int sysnumbhlogopr;/*四元式个数和临时变量个数*/
int truelinkfalselinktchuko;
void pushys(char *stemp) /*运算元素进栈*/
{ int ln;
ln=strlen(stemp);
chstake.s[chstake.top]=(char *)malloc((ln+1)*sizeof(char));
strcpy(chstake.s[chstake.top]stemp);
chstake.top++;
}
void pushsf(char ch1int jb)/*运算符进栈*/
{ ysstake.ch[ysstake.top]=ch1;
ysstake.sjb[ysstake.top]=jb;
ysstake.top++;
}
char *popys() /*运算元素出栈*/
{ char *tp;
chstake.top--;
tp=chstake.s[chstake.top];
chstake.s[chstake.top]=NULL;
return(tp);
}
char popsf() /*运算符出栈*/
{ char ctemp;
ysstake.top--;
ctemp=ysstake.ch[ysstake.top];
return(ctemp);
}
void back(int t1int t2)
{ struct syshi *temp3;
int bh3t0;
bh3=t1;
while(bh3!=0)
{ temp3=yshead.next;
while(temp3->bhao!=bh3) temp3=temp3->next;
sscanf(temp3->s[0]“%d“&bh3);
sprintf(temp3->s[0]“%d“t2);
}
}
void batch()
{ struct syshi *temp1*temp2*temp3;
int bh1bh2bh3i=0;
char ch1;
while(i { bh1=logys.ysbh[i];
temp1=yshead.next;
while(temp1->bhao!=bh1) temp1=temp1->next;
ch1=logfh.ch[i];
if(ch1==‘&‘)
{ bh3=truelink;
truelink=0;
back(bh3bh1+2);
sprintf(temp1->s[0]“%d“bh1+2);
temp1=temp1->next;
sprintf(temp1->s[0]“%d“falselink);
falselink=bh1+1;
}
if(ch1==‘|‘)
{ sprintf(temp1->s[0]“%d“truelink);
truelink=bh1;
temp1=temp1->next;
bh3=falselink;
falselink=0;
back(bh3bh1+2);
sprintf(temp1->s[0]“%d“bh1+2);
}
i++;
}
temp2=yshead.next;
bh2=logys.ysbh[logys.top-1];
while(temp2->bhao!=bh2) temp2=temp2->next;
sprintf(temp2->s[0]“%d“truelink);truelink=bh2;
temp2=temp2->next;
sprintf(temp2->s[0]“%d“falselink);falselink=bh2+1;
logys.top=0;
}
void logysh()
{ struct syshi *temp;
temp=ystail;
temp->next=(struct syshi *)malloc(sizeof(struct syshi));
temp=temp->next;
temp->bhao=100+bh;
logys.ysbh[logys.top++]=100+bh;
bh++;
temp->s[0]=(char *)malloc(8*sizeof(char));
strcpy(temp->s[0]“----“);
temp->s[1]=(char *)malloc(2*sizeof(char));
strcpy(temp->s[1]“ “);
temp->s[2]=(char *)malloc(8*sizeof(char));
sprintf(temp->s[2]“if %s goto“popys());
temp->s[3]=(char *)malloc(2*sizeof(char));
strcpy(temp->s[3]“ “);
temp->next=(struct syshi *)malloc(sizeof(struct syshi));
temp=temp->next;
temp->bhao=100+bh;bh++;
temp->s[0]=(char *)malloc(8*sizeof(char));
strcpy(te
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 17332 2005-01-17 14:22 新建文件夹\run.exe
文件 8977 2005-01-17 14:20 新建文件夹\source.c
文件 80896 2005-01-15 17:00 新建文件夹\翻译.exe
目录 0 2005-03-31 10:35 新建文件夹
----------- --------- ---------- ----- ----
107205 4
- 上一篇:飞机订票系统delphi源代码
- 下一篇:交通旅行模拟
相关资源
- 编译词法分析器识别关键字常数和符
- SAMPLE (类pascal) 词法分析程序 C 版
- Delphi做的用于分析Pascal语言的词法分
- 编译原理LR(0)语法分析
- 编译原理实验:词法分析,语法分析
- 编译原理语法分析器、词法分析器
- pl/0编译器 语法分析
- 哈工大威海-编译原理实验报告和源码
- TINY+编译器 改编自原版TINY
- 情感和语义分析最全中文数据库
- 编译原理课程设计 while do循环语句翻
- 词法分析器 -计算器版
- 天津理工大学编译原理实验2
- 词法语法分析器
- 词法分析器自动生成器 FLEX
- Pascal语义分析器
- 组会ppt 关于 BiSeNet
- 中科院汉语词法分析系统ICTCLAS安装包
- 基于deeplabv3+的遥感农作物语义分割
- 编译原理简单赋值语句的语法分析程
- 编译原理语法分析器课程设计
- 词法分析器Lex(编译原理)
- 杭电编译原理语法分析器
- LR0语法分析器
- 华工编译原理实验词法分析+语法分析
- 翻译 Review on Deep Learning Segmentation 应用
- 词法分析器
- 北方工业大学编译原理话语法分析实
- 编译原理语法分析器课程设计完美版
- 词法分析器有界面
评论
共有 条评论