91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-05-10
  • 語(yǔ)言: C/C++
  • 標(biāo)簽:

資源簡(jiǎn)介

學(xué)生在學(xué)習(xí)《編譯原理》課程設(shè)計(jì)中,結(jié)合各章節(jié)的構(gòu)造編譯程序的基本理論,總共用一周的時(shí)間完成課程設(shè)計(jì)。要求用C或C++語(yǔ)言描述及上機(jī)調(diào)試,實(shí)現(xiàn)五個(gè)題目中任意一個(gè),是學(xué)生將理論與實(shí)際應(yīng)用結(jié)合其,起來(lái),受到軟件設(shè)計(jì)等開(kāi)發(fā)過(guò)程的全面訓(xùn)練,從而提高學(xué)生軟件開(kāi)發(fā)的能力。 能完成指定寄存器個(gè)數(shù)的情況下降一中間代碼程序段翻譯成會(huì)變語(yǔ)言目標(biāo)代碼(匯編指令應(yīng)包括加、減、乘、除),要求指令條數(shù)最少的情況下,盡量使用寄存器,盡量少訪問(wèn)內(nèi)存,這樣才能做到運(yùn)行效率高。

資源截圖

代碼片段和文件信息

#include
#include
#include
char?temp=‘a(chǎn)‘-1;//用于標(biāo)志不同的寄存器?
stack?NumberStack;//堆棧
int?stackPointer;
typedef?struct{
int?operationName;//操作碼?
char?registerName;//使用的寄存器?
char?numberValue;//操作數(shù)?
}OperationStruct;
?
OperationStruct?operations[40];
int?operationNowIndex=0;//表示當(dāng)前是第幾個(gè)操作?
int?registerFlag;//寄存器標(biāo)志:0表示為空,非0,被占用?
char?inputString[40];

//判斷是否為操作符,并將基轉(zhuǎn)換成對(duì)應(yīng)的數(shù)字表示?
int?isOperator(char?ch){
switch(ch){
case?‘+‘:
return?3;
case?‘-‘:
return?4;
case?‘*‘:
return?5;
case?‘/‘:
return?6;
default:
return?0;
}
}

//判斷是否為數(shù)字?
int?isNumber(char?ch){
if(ch>=‘0‘&&ch<=‘9‘)
return?1;
return?0;
}

//根據(jù)運(yùn)算符和當(dāng)前寄存器的狀態(tài),轉(zhuǎn)換成對(duì)應(yīng)的操作?
void?GenerateOperations(char?ch){ //如果是操作符就從棧中彈出兩個(gè)操作數(shù)?
char?x1x2;
x2=NumberStack.top();
NumberStack.pop();
x1=NumberStack.top();
NumberStack.pop();
if(registerFlag==0){ //?如果寄存器沒(méi)被占用,直接生成運(yùn)算指令:X1裝載到R,X2與之進(jìn)行對(duì)應(yīng)的運(yùn)算?
operations[operationNowIndex].operationName=1; //裝載NumberStack[S-1]即x1?到寄存器R
operations[operationNowIndex].registerName=‘R‘;
operations[operationNowIndex].numberValue=x1;
operationNowIndex++;
operations[operationNowIndex].operationName=isOperator(ch); //將操作符變成數(shù)字代碼?
operations[operationNowIndex].registerName=‘R‘;
operations[operationNowIndex].numberValue=x2;
operationNowIndex++;
}else?if(x1!=‘R‘&&x2!=‘R‘&®isterFlag!=0){//x1和x2都不是寄存器的值,且寄存器被占用
temp++; //用一個(gè)新的變量來(lái)保存數(shù)據(jù),比如ab……?
operations[operationNowIndex].operationName=2; //******? *******
operations[operationNowIndex].registerName=‘R‘; //****** 將寄存器中數(shù)據(jù)保存到臨時(shí)變量 *******
operations[operationNowIndex].numberValue=temp; //****** *******
NumberStack.pop();
NumberStack.push(temp); //將臨時(shí)變量壓入堆棧?
operationNowIndex++;
//以上已經(jīng)將寄存器清空了,可以按上一個(gè)條件中的方法進(jìn)行操作了?

operations[operationNowIndex].operationName=1; //和上面一個(gè)條件中的方法一樣?
operations[operationNowIndex].registerName=‘R‘;
operations[operationNowIndex].numberValue=x1;
operationNowIndex++;
operations[operationNowIndex].operationName=isOperator(ch);
operations[operationNowIndex].registerName=‘R‘;
operations[operationNowIndex].numberValue=x2;
operationNowIndex++;
}else?if(x1==‘R‘&&x2!=‘R‘&®isterFlag==(stackPointer-1)){//x1是寄存器,x2是操作數(shù),?直接進(jìn)行操作,因?yàn)橐呀?jīng)有一個(gè)操作數(shù)了?
operations[operationNowIndex].operationName=isOperator(ch);
operations[operationNowIndex].registerName=‘R‘;
operations[operationNowIndex].numberValue=x2;

評(píng)論

共有 條評(píng)論

相關(guān)資源