资源简介
PL/O语言词法分析、语法分析树、语义分析与中间代码生成、解释执行中间代码。
代码片段和文件信息
#include“compileR.h“
void printStr(string buf int startX int startY) {
//在控制台指定位置处输出字符串
HANDLE hd;
COORD pos;
pos.X = startX;
pos.Y = startY;
hd = GetStdHandle(STD_OUTPUT_HANDLE);//获得标准输出的句柄
// SMALL_RECT rc = { 00200 - 1100 - 1 };//窗口位置和大小
// SetConsoleWindowInfo(hd true &rc);
SetConsoleCursorPosition(hd pos);//设置控制台光标输出的位置
cout << buf;
}
int compileProcedure::findKeyword(char *buf) {
//确定该词是否为关键字
if (!strcmp(buf “const“))
return CONSTSYM;
if (!strcmp(buf “var“))
return VARSYM;
if (!strcmp(buf “procedure“))
return PROCSYM;
if (!strcmp(buf “begin“))
return BEGINSYM;
if (!strcmp(buf “end“))
return ENDSYM;
if (!strcmp(buf “odd“))
return ODDSYM;
if (!strcmp(buf “if“))
return IFSYM;
if (!strcmp(buf “then“))
return THENSYM;
if (!strcmp(buf “call“))
return CALLSYM;
if (!strcmp(buf “while“))
return WHILESYM;
if (!strcmp(buf “do“))
return DOSYM;
if (!strcmp(buf “write“))
return WRITESYM;
if (!strcmp(buf “read“))
return READSYM;
return -1;
}
string outputEnum(int type) {
//输出枚举类型实际代表的字符串内容
switch (type) {
case 0:
return “LPAREN“;
break;
case 1:
return “RPAREN“;
break;
case 2:
return “EQ“;
break;
case 3:
return “NEQ“;
break;
case 4:
return “PLUS“;
break;
case 5:
return “MINUS“;
break;
case 6:
return “TIMES“;
break;
case 7:
return “SPLASH“;
break;
case 8:
return “COMMA“;
break;
case 9:
return “SEMICOLON“;
break;
case 10:
return “PERIOD“;
break;
case 11:
return “ASSIGN“;
break;
case 12:
return “COLON“;
break;
case 13:
return “GE“;
break;
case 14:
return “GT“;
break;
case 15:
return “LE“;
break;
case 16:
return “LSS“;
break;
case 17:
return “CONSTSYM“;
break;
case 18:
return “VARSYM“;
break;
case 19:
return “PROCSYM“;
break;
case 20:
return “BEGINSYM“;
break;
case 21:
return “ENDSYM“;
break;
case 22:
return “ODDSYM“;
break;
case 23:
return “IFSYM“;
break;
case 24:
return “THENSYM“;
break;
case 25:
return “CALLSYM“;
break;
case 26:
return “WHILESYM“;
break;
case 27:
return “DOSYM“;
break;
case 28:
return “WRITESYM“;
break;
case 29:
return “READSYM“;
break;
case 30:
return “IDNET“;
break;
case 31:
return “NUMBER“;
break;
default:
return “NOThis“;
break;
}
}
int compileProcedure::GetSym(symbol *oneFILE *file) {
char ch = ‘ ‘;
int pos = 0;
ch = fgetc(file);
char buf[maxIdLength + 1];
while (ch == ‘ ‘ || ch == ‘\t‘ || ch == ‘\r‘ || ch == ‘\n‘) {
if ((ch = fgetc(file)) == EOF) {
//输出常量表和符号表
cout << “符号表输出如下:“ << endl;
for (int i = 0; i < IDSymbol.size(); i++)
cout << IDSymbol[i] << endl;
cout << “常量表输出如下:“ << endl;
for (int i = 0; i < Constant.size(); i++)
cout << Constant[i] << endl;
return 0;
}
}
if (isalpha(ch)) {
while (is
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 38948 2018-12-22 12:43 compilePLO\compileR.cpp
文件 2529 2018-12-10 19:10 compilePLO\compileR.h
目录 0 2018-12-22 16:11 compilePLO
----------- --------- ---------- ----- ----
41477 3
- 上一篇:机器学习4-多元线性回归:数据集与
- 下一篇:进程通信共享内存消息队列
评论
共有 条评论