资源描述:
《if-else条件语句的翻译程序设计(简单优先法、输出四元式)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#include#include#include#includeusingnamespacestd;#defineSTACK_INIT_SIZE50#defineSTACKINCREMENT30#defineOK1#defineERROR-1#defineFAILURE-1////////////
2、///////////////////////////*(1)S->ifEthenBelseB(2)E->(A>A)(3)E->(A(A)(5)A->d(6)A->num(7)B->{d=C}(8)C->A+A(9)C->A-A(10)C->A*A(11)C->A/A(12)C->A*////////////////////////////////////////intlineno=1;charch;intanltable[22][22]={/*S*/{0,0,0,0,0,0,0,0
3、,0,0,0,0,0,0,0,0,0,0,0,0,0,2},/*if*/{0,0,3,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*E*/{0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*then*/{0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},/*B*/{0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},/*else*/{0,0,0,
4、0,3,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},/*(*/{0,0,0,0,0,0,0,0,0,0,0,3,1,1,0,0,0,0,0,0,0,0},/*)*/{0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},/*>*/{0,0,0,0,0,0,0,0,0,0,0,3,1,1,0,0,0,0,0,0,0,0},/*<*/{0,0,0,0,0,0,0,0,0,0,0,3,1,1,0,0,0,0,0,0,0,0},/*=*/{0,0,
5、0,0,0,0,0,0,0,0,0,1,1,1,3,0,0,0,0,0,0,0},/*A*/{0,0,0,0,0,0,0,3,3,3,0,0,0,0,0,0,2,3,3,3,3,0},/*d*/{0,0,0,0,0,0,0,2,2,2,3,0,0,0,0,0,2,2,2,2,2,0},/*num*/{0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,2,2,2,2,2,0},/*C*/{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0},/*{*/{
6、0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0},/*}*/{0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},/*+*/{0,0,0,0,0,0,0,0,0,0,0,3,1,1,0,0,0,0,0,0,0,0},/*_*/{0,0,0,0,0,0,0,0,0,0,0,3,1,1,0,0,0,0,0,0,0,0},/***/{0,0,0,0,0,0,0,0,0,0,0,3,1,1,0,0,0,0,0,0,0,0},/*/*
7、/{0,0,0,0,0,0,0,0,0,0,0,3,1,1,0,0,0,0,0,0,0,0},/*#*/{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},};//0-error,1=<,2=>,3==charallname[30][30];//单词全名charout[30][30];//保存单词简称intlength;structatt{//名字表类型stringsname;charselect;charaddre;};attattname[40];//名字表
8、typedefstructSqStack{char*base;char*top;intstacksize;}SqStack;//栈定义voidInitStack(SqStack&S){//栈初始化S.base=(char*)malloc(STACK_INIT_SIZE*sizeof(char));//分配存储空间if(!S.base)exit(OVERFLOW);//为栈S分配存储空间失败S.top=S.base;S.stacksize=STACK_IN