资源简介
c0文法的编译器,词法分析, 文法分析,目标代码生成,目标代码的执行系统一应俱全。为北航编译技术的课程设计之一。
另有c0文法编译器的java实现,包含代码优化(dag图优化,删除公共子表达式、删除无效赋值等)、寄存器分配,目标代码为汇编码。需要者请单独跟本人联系。
代码片段和文件信息
#include
#include
#include
#include
#include“Compiler.h“
char name[MAXC][MAXWORD]; //用来存储标识符
int NumOfC=1; //符号表内元素的个数
Character Symlist[MAXC]; //符号表
int numoflev[MAXLEV]; //各层的表中变量数
opr pcode[MAXOP]; //存Pcode指令
int oprnum; //指令数
int stack[MAXGO]; //Pcode解释执行阶段的堆栈
int dl[MAXGOLEV]bl[MAXGOLEV]; //stack堆栈运行过程中的指针
int linenum=1; //源程序每行的代号
int errornum=0error[MAXERROR]errorline[MAXERROR];
int gonum=0dlnum=0blnum=0;
int type=0;
int snum=0;
int start;
int lev=1;
int breakoprIsbreak=0;
int typeofexp1=11 typeofexp2=12;
int oprnumcase=0;
int Isret=1;
//字符获取和处理
int getsym()
{
char chtmp;
int ijm;
ch=fgetc(FIN);
while(isspace(ch))//处理空格
{
putc(chFOUT);
if(ch==‘\n‘)
{
linenum++;
printf(“%d:\t“linenum);
}
ch=fgetc(FIN);
}
i=0;
Word[i]=ch;
i++;
//token处理
if(isalpha(ch))
{
putc(chFOUT);
ch=fgetc(FIN);
while(isalpha(ch)||isdigit(ch)||(ch==‘_‘)) //加入下划线
{
Word[i]=ch;
i++;
/*if(i==MAXWORD)
{
errorline[errornum]=linenum;
error[errornum++]=1;
i--;
Word[i]=‘\0‘;
putc(chFOUT);
ch=fgetc(FIN);
while(isalpha(ch)||isdigit(ch))
{
putc(chFOUT);
}
ungetc(chFIN);
return 1;//是标识符
}*/
putc(chFOUT);
ch=fgetc(FIN);
}
ungetc(chFIN);
Word[i]=‘\0‘;
for(m=0;m {
if(!(strcmp(Keyword[m]Word))) //读取的字符串符合对key word的判断
{
if(m+10==12)
return 1;
return m+10;//返回相应的keyword的对应数字
}
}
if(m==kk){
return 1;//不是key word是标识符
}
}
//数值处理
if(isdigit(ch))
{
putc(chFOUT);
while(isdigit((ch=fgetc(FIN))))
{
putc(chFOUT);
Word[i++]=ch;
if(i==MAXWORD)
{
errorline[errornum]=linenum;
error[errornum++]=1;
Word[--i]=‘\0‘;
ch=fgetc(FIN);
while(isdigit(ch))
{
putc(chFOUT);
}
num=atoi(Word);//将字符串转化为对应的数字
ungetc(chFIN);
return 2;//是数字
}
}
ungetc(chFIN);
Word[i]=‘\0‘;
num=atoi(Word);//将字符串转化为对应的数字
return 2;//是数字
}
//分界符
i=34;
putc(chFOUT);
switch(ch){
case‘\‘‘:
ch=fgetc(FIN);
if(ch==‘+‘||ch==‘-‘||ch==‘*‘||ch==‘\‘‘||isalpha(ch)) //对应于printf语句中的各种参数
{
cischar=ch;
putc(chFOUT);
if ((ch=fgetc(FIN))==‘\‘‘)
{
putc(chFOUT);
return 4;//字符
}
else
{
putc(chFOUT);
errorline[errornum]=linenum;
error[errornum++]=3;
return -1;
}
}
case‘“‘:
j=0;
while((ch=fgetc(FIN))!=‘“‘)//若不是非空串
{
putc(chFOUT);
sisstring[j++]=ch;
if(j==MAXLENGTH)
{
printf(“warning!字符串过长\n“);
sisstring[--j]=‘\0‘;
putc(chFOUT);
ch=fgetc(FIN);
while(ch!=‘“‘)
{
putc(chFOUT);
j++;
if(ch==EOF||j>100) //字符串过长或缺少反引号
{
errorline[errornum]=linenum;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 36246 2009-04-11 21:19 Compiler.cpp
文件 4263 2009-04-11 21:24 Compiler.h
----------- --------- ---------- ----- ----
40509 2
- 上一篇:JSP+SQL水费管理系统
- 下一篇:CMM 解释器JAVA实现)
相关资源
- java实现的c语言简单编译器
- C编译器java编写词法分析,语法分析,
- java模拟编译器实现词法语法分析生成
- C0编译器java实现
- JAVA版本的LALR编译器语法分析
- JAVA课程设计PL0编译器
- 编译原理第二版 龙书
- 清华大学编译课decaf编译器源码
- j67rc0.jar
- TPL编译器.zip
- JAVA写的编译器编译原理课设
- java写的c语言编译器
- 一个java实现的简易编译器
- MIPS反编译器与模拟器使用JAVA
- pc0123机器码修改工具
- PL0编译器java版
- src083
- AndroidKiller小插件,多dex转java源码,无
- Java反编译工具(XJad) v2.2 中文绿色版
- PL/0编译器(Java)
- java实现的简单的编译器
- java编译器源代码
- PL/0语言编译器源程序山东大学编译原
- 编译原理课程设计 java实现编译器
- JAVA编译器,适合初学者
- java 反编译器 class文件反编译成java源
评论
共有 条评论