编译课程设计报告书(5)

2018-12-05 13:26

cout<<\ exit(0); } else {

s.DispStack(); if(a=='!')

cout<<\ else

cout<<\ s.PushStack(a); strp++;

statop=s.Getsize()-1; } }

s.DispStack(); s.PopStack(3); if(s.Getsize()==0)

cout<<\ else

cout<<\

}

20

(3)运行结果 1)正确情况下

21

2)不正确的情况下:

22

3.3.基于算符优先分析方法的语法制导翻译程序的设计 (1)流程图 开始 输出优先关系表 输入字符串 ‘#’压栈 当前字符为Y 栈中为N ‘#’ ? “#N#” 不是句子 N Y 栈顶终结符与当前字出栈 符比较 N 是句子 大于? Y 结束 规约 入栈 判断产生式类型 为前三个产生 式? Y 生成产生式 下一个字符 23

(2)程序 #include #include using namespace std; const int MAX=100;

char cost[8][8]={' ','+','*','!','i','(',')','#', '+','>','<','<','<','<','>','>', '*','>','>','<','<','<','>','>', '!','>','>','<','<','<','>','>', 'i','>','>','>',' ',' ','>','>', '(','<','<','<','<','<','=',' ', ')','>','>','>',' ',' ','>','>',

'#','<','<','<','<','<',' ','='};//the priority realiton graph int Digital[MAX]; //store the letter swap to digital int Dp=0; //the pointer of the digital char Sign[MAX]; //strore the sign of the string int Sp=0; //the pointer of the sign int Temp[MAX]; // int Tp; //

int Fp=0; //point to the four equation space void DispCost(); bool IsChar(char c);

int SearchCost(int i,int j); int Entry(char ch); int NewTemp(int t[3]);

int CharToDigital(char ch); void DispItem(int i); void DispIndirect(int i); int Merge(int *ch,int ll);

void ToDigital(int digital[],char str[],int &d_len,int len); typedef class four_item {

char op;

int s1,s2,s3; public:

four_item(){}

four_item(int op,int s1,int s2) {

this->op=cost[0][op]; this->s1=s1; this->s2=s2;

this->s3=Fp+300;//metion +100 ,+200,+300

24


编译课程设计报告书(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:C14020 证券投资研究的直接目标是寻找预期差 90分

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: