资源简介
功能完整的PL0编译器,附带多个测试用例,可以用于编译技术课程实践参考

代码片段和文件信息
// pl0 compiler source code
#include
#include
#include
#include
#include “set.h“
#include “pl0.h“
char total[MAXIDLEN + 1];
//#include “set.c“
int flag1=0sign=0;
//////////////////////////////////////////////////////////////////////
// print error message.
//出错处理
void error(int n)
{
int i;
printf(“ “);
for (i = 1; i <= cc - 1; i++)
printf(“ “);
fprintf(outfile “ “);
fprintf(outfile “^\n“);
printf(“^\n“);
fprintf(outfile “Error %3d: %s\n“ n err_msg[n]);
printf(“Error %3d: %s\n“ n err_msg[n]);
err++;
} // error
//////////////////////////////////////////////////////////////////////
//获取下一个字符
void getch(void)
{
if (cc == ll)
{
if (feof(infile))
{
printf(“\nPROGRAM INCOMPLETE\n“);
exit(1);
}
ll = cc = 0;
fprintf(outfile “%5d “ cx);
printf(“%5d “ cx);
while ( (!feof(infile)) // added & modified by alex 01-02-09
&& ((ch = getc(infile)) != ‘\n‘))
{
fprintf(outfile “%c“ ch);
printf(“%c“ ch);
line[++ll] = ch;
} // while
fprintf(outfile “\n“);
printf(“\n“);
line[++ll] = ‘ ‘;
}
ch = line[++cc];
} // getch
//////////////////////////////////////////////////////////////////////
// gets a symbol from input stream.
void zhushi()
{
while(ch!=‘*‘)
{
getch();
}
if(ch==‘*‘)
{
getch();
if(ch==‘)‘)
getch();
else
{
zhushi();
}
}
else
{
error(27); //报错
}
}
//////////////////////////////////////////////////////////////////////
// gets a symbol from input stream.
//词法分析,获取下一个标识符
void getsym(void)
{
int i k;
char a[MAXIDLEN + 1];
while (ch == ‘ ‘|| ch == ‘\t‘)
// modified by yzhang 02-03-12add some white space
getch();
if (isalpha(ch))
{ // symbol is a reserved word or an identifier.
k = 0;
do
{
if (k < MAXIDLEN)
a[k++] = ch;
getch();
}
while (isalpha(ch) || isdigit(ch));
a[k] = 0;
strcpy(id a);
word[0] = id;
i = NRW;
while (strcmp(id word[i--]));
if (++i)
sym = wsym[i]; // symbol is a reserved word
else
sym = SYM_IDENTIFIER; // symbol is an identifier
}
else if (isdigit(ch))
{ // symbol is a number.
k = num = 0;
sym = SYM_NUMBER;
do
{
num = num * 10 + ch - ‘0‘;
k++;
getch();
}
while (isdigit(ch));
if (k > MAXNUMLEN)
error(25); // The number is too great.
}
else if (ch == ‘:‘)
{
getch();
if (ch == ‘=‘)
{
sym = SYM_BECOMES; // :=
getch();
}
else
{
sym = SYM_COLON; // illegal?
}
}
else if (ch == ‘>‘)
{
getch();
if (ch == ‘=‘)
{
sym = SYM_GEQ; // >=
getch();
}
else
{
sym = SYM_GTR; // >
}
}
else if (ch == ‘<‘)
{
getch();
if (ch == ‘=‘)
{
sym = SYM_LEQ; // <=
getch();
}
else if (ch == ‘>‘)
{
sym = SYM_NEQ; // <>
getch();
}
else
{
sym = SYM_LES; // <
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-07-19 14:04 pl0\Debug\
文件 14846 2012-07-19 14:04 pl0\Debug\BuildLog.htm
文件 444 2004-08-27 22:30 pl0\Debug\hbin.txt
文件 67 2012-07-19 14:04 pl0\Debug\mt.dep
文件 393216 2012-07-19 14:04 pl0\Debug\pl0.exe
文件 406 2012-07-19 13:50 pl0\Debug\pl0.exe.em
文件 472 2012-07-19 13:50 pl0\Debug\pl0.exe.em
文件 381 2012-07-19 14:04 pl0\Debug\pl0.exe.intermediate.manifest
文件 242156 2012-07-19 14:04 pl0\Debug\pl0.ilk
文件 71198 2012-07-19 14:04 pl0\Debug\pl0.obj
文件 1936384 2012-07-19 14:04 pl0\Debug\pl0.pdb
文件 8720 2012-07-19 13:50 pl0\Debug\set.obj
文件 1641 2004-08-27 22:30 pl0\Debug\test.out
文件 233 2004-08-27 22:25 pl0\Debug\test.pl0
文件 0 2004-08-27 22:21 pl0\Debug\test.pl0.bak
文件 41984 2012-07-18 10:35 pl0\Debug\vc60.idb
文件 53248 2012-07-18 10:35 pl0\Debug\vc60.pdb
文件 44032 2012-07-19 14:04 pl0\Debug\vc90.idb
文件 61440 2012-07-19 14:04 pl0\Debug\vc90.pdb
文件 832 2012-07-18 10:35 pl0\hbin.txt
文件 27237 2012-07-19 14:23 pl0\pl0.c
文件 4420 2004-08-27 22:34 pl0\pl0.dsp
文件 529 2004-08-27 22:34 pl0\pl0.dsw
文件 5613 2012-07-18 10:19 pl0\pl0.h
文件 470016 2012-07-19 14:23 pl0\pl0.ncb
文件 48640 2012-07-18 10:36 pl0\pl0.opt
文件 893 2012-07-18 10:35 pl0\pl0.plg
文件 871 2012-07-19 13:50 pl0\pl0.sln
文件 9728 2012-07-19 14:23 pl0\pl0.suo
文件 5632 2012-07-19 13:50 pl0\pl0.vcproj
文件 1409 2012-07-19 14:23 pl0\pl0.vcproj.LENOVO.Administrator.user
............此处省略10个文件信息
- 上一篇:西工大计算机组成原理试题22套
- 下一篇:Linux设备驱动模型详解
相关资源
- CVSNT 完整覆盖版防TortoiseCVS中文乱码
- 微软masm汇编编译器
- 类pascal语言编译器(编译原理实验)
- BCG帮助手册,完整版_修正
- 交通咨询模拟系统完整代码
- 网上拍卖系统完整源代码
- STM32F103 串口程序(完整版)
- 可拖拽的甘特图控件(完整)
- 编译原理课程设计:词法语法编译器
- 武汉理工大学 单片机课程设计 16*16点
- 完整的项目案例
- 完整版家庭在线记账理财管理系统
- 国际象棋c 完整版
- 一个比较完整的开源cad 图形程序
- STM32F103 CC2500完整驱动(模拟SPI)
- 30秒倒计时器完整版下载
- 操作系统课程设计完整版
- 汇编语言编译器masm5.0
- 《编译原理》清华大学版中的pl0扩充
- 这是一个套完整的综合布线系统方案
- 学生成绩管理系统C 源码(很完整)
- 捆绑源码发布 捆绑软件源码 完整版
- C编译器源代码(超级牛b).rar
- 基于Petri网的工作流(完整的原创源代
- 典当综合业务管理系统(完整版)
- 《原子物理学》高教 杨福家 完整版课
- DOS命令大全(完整版)
- SX126x_LORA驱动程序(包含完整的工程文
- 计算机操作系统(第四版)汤小丹课
- xlrd-1.2.0完整包
评论
共有 条评论