欢迎来到天天文库
浏览记录
ID:10811635
大小:127.00 KB
页数:12页
时间:2018-07-08
《plx编译器软件设计说明书(1)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Plx编译器软件设计说明书作者:王毅群日期:08/01/061.介绍对PL/X语言,编写其编译器。完成了词法分析、语法分析、出错处理、代码生成和解释程序。2.编译器系统结构2.1编译器2.1.1PL/X语法图programdsbeginssend.dd;ss;aidentaident,bidentbident,integerlogicalprogdsssdaeatat-+-atafaf*/aidentnumberae)(afbebtbtorbtbfbfandbidentbe)(bfretruefalsenotbfreaident=num
2、ber>>=<<=/=aesarrayidentaidentbident:=:=:=aeaebeifbethenssendelsesswhilebedossendrepeatssuntilbewriteaereadaident2.1.2判断是否符合两条限制规则经验证,符合。2.1.3语法出错表定义编号含义0numbertoolarge1needkeyword'program'here2needkeyword'begin'here3needkeyword'end'here4needaidentifierhere5identifiernot
3、defined6need':='here7needkeyword'then'here8needkeyword'do'here9needkeyword'until'here10needoneof'if','while','repeat','write',aident,bidenthere11needaidenthere,notbident12need')'here13needoneof'(',aident,numberhere14needoneofaident,numberhere15needoneof'=','>','>=','<','
4、<='here2.2虚拟机2.2.1虚拟机指令格式COMMANDparam2.2.2虚拟机指令系统及其解释INT//给变量预留位置LIT//目标指令,把一个常数置入栈顶LOD//目标指令,把一个变量置入栈顶STO//目标指令,从栈顶把一个数置入到一个变量里JMP//目标指令,无条件转移JPC//目标指令,有条件转移(当条件为0时转移)OPR//目标指令,算术和关系运算WRT//目标指令,打印栈顶数据OPR_PLUS//+OPR_MINUS//-OPR_TIMES//*OPR_SLASH///OPR_OPPO//取负OPR_EQL//=O
5、PR_LSS//OPR_GEQ//>=OPR_OR//orOPR_AND//andINT:stackCount=code[i].offset;LIT:dataStack[stackCount++]=code[i].offset;LOD:dataStack[stackCount++]=dataStack[code[i].offset];STO:dataStack[code[i].offset]=dataStack[--stackCount];JMP:i=code[i].offset;JPC:if
6、(dataStack[--stackCount]==FALSE)i=code[i].offset;OPR_PLUS:dataStack[stackCount-2]=dataStack[stackCount-2]+dataStack[stackCount-1];stackCount--;OPR_MINUS:dataStack[stackCount-2]=dataStack[stackCount-2]-dataStack[stackCount-1];stackCount--;OPR_TIMES:dataStack[stackCount-2]
7、=dataStack[stackCount-2]*dataStack[stackCount-1];stackCount--;OPR_SLASH:dataStack[stackCount-2]=dataStack[stackCount-2]/dataStack[stackCount-1];stackCount--;OPR_OPPO:dataStack[stackCount-1]=-dataStack[stackCount-1];caseOPR_EQL:if(dataStack[stackCount-2]==dataStack[stackC
8、ount-1])dataStack[stackCount-2]=TRUE;elsedataStack[stackCount-2]=FALSE;stackCount--;OPR_LSS:if(dataStac
此文档下载收益归作者所有