资源描述:
《PL0源程序-编译原理实验代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、附件1小组成员:程序清单Main.c#include#include#includevoiderror(intn);voidgetsym();//voidenter(enumobjectk,int*ptx,intlev,int*pdx);intposition(char*idt,inttx);intconstdeclaration(int*ptx,intlev,int*pdx);intvardeclaration(int*ptx,intlev,int*pdx);intfacto
2、r(int*ptx,intlev);intterm(int*ptx,intlev);intexpression(int*ptx,intlev);intstatement(int*ptx,intlev);intblock();enumobject{constant,variable,procedure};structtab{charname[14];enumobjectkind;intval;intlevel;intadr;intsize;}table[100];enumsymbol{nul,ident,number,plus,minu
3、s,times,slash,oddsym,eql,neq,lss,leq,gtr,geq,lparen,rparen,comma,semicolon,period,becomes,beginsym,endsym,ifsym,thensym,whilesym,writesym,readsym,dosym,callsym,constsym,varsym,procsym,progsym,};enumsymbolsym=nul;enumsymbolmulop;enumsymbolwsym[14];enumsymbolssym[256];cha
4、rch='';char*str;charword[14][10]={"begin","call","const","do","end","if","odd","procedure","program","read","then","var","while","write"};//设置保留字名字intnum;intlev=0;inttx=0;intk;int*mm;//=(int*)malloc(sizeof(int));char*id,sign[14];chara[14];FILE*fp1,*fp2,*fp3;voiderror(in
5、tn){switch(n){case1:printf("常数说明中的"="写成了":="。");break;case2:printf("常数说明中"="后应是数字。");break;case3:printf("常数说明中的标识符后应是"="。");break;case4:printf("program,const,var,procedure后应为标识符。");break;case5:printf("漏掉了","或";"。");break;case6:printf("过程说明的符号不正确。
6、");break;case7:printf("应该是语句的开始符。");break;case8:printf("程序体内语句部分的后跟符不正确。");break;case9:printf("程序的结尾丢了句号"."。");break;case10:printf("语句之间漏了";"。");break;case11:printf("标识符未说明。");break;case12:printf("赋值语句中,赋值号左部标识符属性应是变量。");break;case13:printf("赋值语句左部标识符后应是
7、赋值号":="。");break;case14:printf("call后应为标识符。");break;case15:printf("call后标识符属性应为过程。");break;case16:printf("条件语句中丢了"then"。");break;case17:printf("丢了"end"或";"。");break;case18:printf("while型循环语句中丢了"do"。");break;case19:printf("语句后的符号不正确。");break;case2
8、0:printf("应为关系运算符。");break;case21:printf("表达式内标识符属性不能是过程。");break;case22:printf("表达式中漏掉右括号")"。");break