资源简介
c语言实现pl0编译器的扩充:
if 条件 then 语句 else 语句
for 变量=初始值 to 终止值 begin 语句 end
dowhile 语句 until 条件
代码片段和文件信息
/*
* PL/0 complier program for win32 platform (implemented in C)
*
* The program has been test on Visual C++ 6.0 Visual C++.NET and
* Visual C++.NET 2003 on Win98 WinNT Win2000 WinXP and Win2003
*
* 使用方法:
* 运行后输入PL/0源程序文件?
* 回答是否输出虚拟机代码
* 回答是否输出名字表
* fa.tmp输出虚拟机代码
* fa1.tmp输出源文件及其各行对应的首地址
* fa2.tmp输出结?
* fas.tmp输出名字表
*/
#include
#include “pl0.h“
#include “string.h“
/* 解释执行时使用的栈 */
#define stacksize 500
int main()
{
bool nxtlev[symnum];
printf(“Input pl/0 file? “);
scanf(“%s“ fname); /* 输入文件名 */
fin = fopen(fname “r“);//char fname[al];
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“Input 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(nxtlev declbegsys statbegsys symnum);
nxtlev[period] = true;
if(-1 == block(0 0 nxtlev)) /* 调用编译程序 */
{
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“);
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;
/* 设置保留字名字按照字母顺序,便于折半查找 */
strcpy(&(word[0][0]) “begin“);
strcpy(&(word[1][0]) “call“);
strcpy(&(word[2][0]) “const“);
strcpy(&(word[3][0]) “do“);
strcpy(&(word[4][0]) “dowhile“);
strcpy(&(word[5][0]) “else“);//************添加else*****************************************************
strcpy(&(word[6][0]) “end“);
strcpy(&(word[7][0]) “for“);//*****************for*****
strcpy(&(word[8][0]) “if“);
strcpy(&(word[9][0]) “odd“);
strcpy(&(word[10][0]) “procedure“);
strcpy(&(word[11][0]) “read“);
strcpy(&(word[12][0]) “then“);
strcpy(&(word[13][0]) “to“);//*****************to*****
strcpy(&(word[14][0]) “until“);
strcpy(&(word[15][0]) “var“);
strcpy(&(word[16][0]) “while“);
strcpy(&(word[17][0]) “write“);
/* 设置保留字符号 即begin对应beginsym...*/
wsym[0] = beginsym;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 31525 2009-12-08 01:19 pl0.c
文件 4848 2009-12-07 20:50 pl0.h
文件 61 2009-12-07 20:35 for.PL0
文件 89 2009-12-08 00:50 dowhile.PL0
文件 110 2009-12-08 01:18 else.pl0
----------- --------- ---------- ----- ----
36633 5
- 上一篇:快速傅里叶变换_C语言代码
- 下一篇:pgm数据读取与保存
相关资源
- C语言编程常见问题解答.pdf
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- 个人日常财务管理系统(C语言)
- c语言电子商务系统
- 小甲鱼C语言课件 源代码
- 将图片转换为C语言数组的程序
- C语言实现的一个内存泄漏检测程序
- DES加密算法C语言实现
- LINUX下命令行界面的C语言细胞游戏
- 用单片机控制蜂鸣器播放旋律程序(
- 学校超市选址问题(数据结构C语言版
- 电子时钟 有C语言程序,PROTEUS仿真图
川公网安备 51152502000135号
评论
共有 条评论