资源简介
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语言嵌入式Modbus协议栈,支持主站和
- C语言封装的HttpClient接口
- C语言课设计算器
- C语言 学生兴趣管理系统
- c语言实现火车订票系统(控制台)源
- 模拟笔记本电脑(C语言实现)
- c语言实现竞技比赛打分系统
- KMP算法C语言程序
- Linux c语言 学生成绩管理系统
- 弹跳的小球(test.c)
- 林锐—高质量C编程
- 基于c语言的通讯录系统
- C语言全套课件与教学资料-哈工大
- 计算机二级C语言真题.docx
- C语言实现 设备信息管理系统
- GBT 28169-2011 嵌入式软件 C语言编码规范
- C语言标准库函数大全.chm
- C语言常用代码(分章节)
- c语言课程设计:客房登记系统源码
- C语言常用算法源代码
- 吕鑫:VS2015之博大精深的0基础C语言视
- c语言文都讲义2020
- c语言课件56883
- C语言推箱子win控制台
- C语言程序设计50例.docx
- 烟花优化算法(c语言版)
- C语言程序设计教材习题参考答案.do
- 数据结构(C语言版)ppt课件,清华,
- c语言编程经典例题100例 word版
- C语言编译器的设计与实现.doc
评论
共有 条评论