资源简介
扩展了一些功能,++,--,*=,/=,取反,取余,一维数组,for循环,while循环,write包含换行,可以输出文本等功能,里面有具体的测试例子

代码片段和文件信息
/*带详细注释的C语言版本PL/0编译程序
*编译和运行环境:
*1Visual C++6.0VisualC++.NET and Visual C++.NET 2003
*WinNT Win2000 WinXP and Win2003
*2 gcc version 3.3.2 20031022(Red Hat Linux 3.3.2-1)
*Redhat Fedora core 1
*Intel 32 platform
*使用方法:
*运行后输入PL/0 源程序文件名
*回答是否输出虚拟机代码
*回答是否输出名字表
*fa.tmp 输出虚拟机代码
*fa1.tmp 输出源文件及其各行对应的首地址
*fa2.tmp 输出结果
*fas.tmp 输出名字表
*/
#include
#include“pl0.h“
#include“string.h“
/*解释执行时使用的栈*/
#define stacksize 500
char WORDS[200][20]; //用于记录文本最多200条
int W=0; //用来记录文本的个数
int CXb=300; //用来break跳转
int CXc=400; //用来continue跳转
int I=1000; //a:=++b; 用来保存a在字母表的位置
int Ia=1000; //同上,用来临时保存
int main()
{
bool nxtlev[symnum];
printf(“Input pl/0 file ?“);
scanf(“%s“fname); /*输入文件名*/
fin=fopen(fname“r“);
if(fin)
{
printf(“List object code ?(Y/N)“); /*是否输出虚拟机代码*/
scanf(“%s“fname);
listswitch=(fname[0]==‘y‘||fname[0]==‘Y‘);
printf(“List symbol table ? (Y/N)“); /*是否输出名字表*/
scanf(“%s“fname);
tableswitch=(fname[0]==‘y‘||fname[0]==‘Y‘);
fa1=fopen(“fa1.tmp““w“);
fprintf(fa1“Iput pl/0 file ?“);
fprintf(fa1“%s\n“ fname);
init(); /*初始化*/
err=0;
cc=cx=ll=0;
ch=‘ ‘;
if(-1!=getsym())
{
fa=fopen(“fa.tmp““w“);
fas=fopen(“fas.tmp““w“);
addset(nxtlevdeclbegsysstatbegsyssymnum);
nxtlev[period]=true;
if(-1==block(00nxtlev)) /*调用编译程序*/
{
fclose(fa);
fclose(fa1);
fclose(fas);
fclose(fin);
printf(“\n“);
return 0;
}
fclose(fa);
fclose(fa1);
fclose(fas);
if(sym!=period)
{
error(9);
}
if(err==0)
{
fa2=fopen(“fa2.tmp“ “w“);
interpret();
fclose(fa2);
}
else
{
printf(“Errors in pl/0 program“);
}
}
fclose(fin);
}
else
{
printf(“Can‘t open file! \n“);
}
printf(“\n“);
//printf(“%s“WORDS);
return 0;
}
/*
*初始化
*/
void init()
{
int i;
for(i=0;i<=255;i++)
{
ssym[i]=nul;
}
ssym[‘+‘]=plus;
ssym[‘-‘]=minus;
ssym[‘*‘]=times;
ssym[‘/‘]=slash;
ssym[‘(‘]=lparen;
ssym[‘)‘]=rparen;
ssym[‘=‘]=eql;
ssym[‘‘]=comma;
ssym[‘.‘]=period;
ssym[‘#‘]=neq;
ssym[‘;‘]=semicolon;
ssym[‘%‘]=percent; ///////////// 取余
ssym[‘~‘]=not; ///////////// 取反
ssym[‘“‘]=words; ///////////// 文本
/*设置保留字名字按照字母顺序便于折半查找*/
strcpy(&(word[0][0])“begin“);
strcpy(&(word[1][0])“break“);
strcpy(&(word[2][0])“call“);
strcpy(&(word[3][0])“const“);
strcpy(&(word[4][0])“continue“);
strcpy(&(word[5][0])“do“);
strcpy(&(word[6][0])“else“); //增加else
strcpy(&(word[7][0])“end“);
strcpy(&(word[8][0])“for“); //增加for
strcpy(&(word[9][0])“if“);
strcpy(&(word[10][0])“odd“);
strcpy(&(word[11][0])“procedure“);
strcpy(&(word[12][0])“read“);
strcpy(&(word[13][0])“sqrt“);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-11 00:05 pl0\
目录 0 2019-01-10 11:41 pl0\Debug\
文件 66 2014-01-03 09:10 pl0\Debug\fa.tmp
文件 130 2014-01-03 09:10 pl0\Debug\fa1.tmp
文件 91 2014-01-03 09:10 pl0\Debug\fas.tmp
文件 217165 2019-01-10 11:10 pl0\Debug\pl0.exe
文件 865788 2019-01-10 11:10 pl0\Debug\pl0.ilk
文件 76478 2019-01-10 11:10 pl0\Debug\pl0.obj
文件 230184 2019-01-10 11:10 pl0\Debug\pl0.pch
文件 558080 2019-01-10 11:10 pl0\Debug\pl0.pdb
文件 164864 2019-01-10 11:11 pl0\Debug\vc60.idb
文件 86016 2019-01-10 11:10 pl0\Debug\vc60.pdb
文件 0 2019-01-10 11:11 pl0\fa.tmp
文件 410 2019-01-10 11:11 pl0\fa1.tmp
文件 21 2019-01-10 11:11 pl0\fa2.tmp
文件 0 2019-01-10 11:11 pl0\fas.tmp
文件 61719 2019-01-10 11:10 pl0\pl0.cpp
文件 3365 2019-01-10 11:10 pl0\pl0.dsp
文件 531 2019-01-10 11:41 pl0\pl0.dsw
文件 4959 2019-01-09 22:30 pl0\pl0.h
文件 17920 2019-01-09 22:18 pl0\pl0.h.doc
文件 66560 2019-01-10 11:41 pl0\pl0.ncb
文件 48640 2019-01-10 11:41 pl0\pl0.opt
文件 731 2019-01-10 11:10 pl0\pl0.plg
文件 529 2007-11-23 15:47 pl0\pl0.txt
文件 29713 2018-11-24 15:03 pl0\pl0源程序.docx
文件 516 2007-11-26 12:40 pl0\Test.cpp
文件 237 2007-09-28 14:04 pl0\test.txt
文件 759 2019-01-09 22:30 pl0\test0.txt
文件 180 2019-01-08 21:16 pl0\test1.txt
文件 178 2019-01-10 23:07 pl0\testchengdeng.txt
............此处省略14个文件信息
- 上一篇:PCB Logo Creator.zip
- 下一篇:Cimatron完美后处理
相关资源
- 编译原理实验工具及参考源码(lex&
- 类pascal语言编译器(编译原理实验)
- 编译原理课程设计:词法语法编译器
- 中科院 编译原理 习题及解答
- 编译原理四元式和逆波兰式
- 《编译原理》清华大学版中的pl0扩充
- PL/0功能扩充break功能
- 编译原理LR(0)语法分析
- 编译原理中间代码生成程序
- 编译原理:LR分析程序
- 编译原理实验:词法分析,语法分析
- 吉林大学编译原理课件
- 编译原理龙书答案
- 编译原理 第三章课后习题答案
- 易语言变量和数组的编译原理
- 编译原理语法分析器、词法分析器
- 山东大学编译原理PL/0语言 compiler实验
- FOR循环语句的翻译程序设计简单优先
- NFA的确定化NFA->DFA完整可运行代码
- 哈工大威海编译原理实验报告和源代
- 哈工大威海-编译原理实验报告和源码
- 编译原理课设c编译器
- 赋值语句翻译四元式
- 河北工业大学编译原理实验代码及实
- 编译原理课程设计 while do循环语句翻
- 编译原理课程设计do——while简单优先
- 南开大学编译原理课件及作业
- 华工往年编译原理试卷
- 编译原理课程设计for循环LR法三元式
- 哈工程-编译原理课程设计(2016级)
评论
共有 条评论