📄 赋值.cpp
字号:
#include"头文件.h"
extern int nowaddress;//表示下一个地址
extern bianYi parse; //词法分析
extern int c; //临时变量的后缀
extern item sign; //
extern fuzhi_stack FUZHI_STACK;//赋值栈
extern fouryuan FOMO; //四元组表
extern valuetable VT; //变量表
int fuzhibiao[numfuzhi+1][numfuzhi+1]={-2,1,1,1,1,1,1,-2,1,
-1,1,1,-1,-1,-2,1,-1,1,
-1,1,1,-1,-1,-2,1,-1,1,
-1,1,1,1,1,-2,1,-1,1,
-1,1,1,1,1,-2,1,-1,1,
-1,-1,-1,-1,-1,-2,1,-1,1,
-1,-1,-1,-1,-1,-1,0,-1,-2,
-1,-1,-1,-1,-1,-1,-2,-1,0,
-2,1,1,1,1,1,1,1,1
};
state mulsentence(){
state temp;
switch(sign.x){
case 3:
{
getnextsign();
temp=sentencelist();
if(sign.x!=12)error();
FOMO.load(nowaddress,sign,sign,sign,sign);
break;
}
default:error();
}
return temp;
}
state sentencelist(){
state temp=sentence();
state temp2=sentencetemp();
FOMO.writeback(temp.chain,temp2.codebegin);
return temp2;
}
state sentencetemp(){
state temp;
switch(sign.x){
case 52:{
getnextsign();
if(sign.x==12)return temp;///没想好
sentencelist();
break;
}
default:break;
}
return temp;
}
void fuzhi_stack::fuzhi_clear(){
fuzhitop=0;
optop=0;
}
fuzhi_stack::fuzhi_stack(){
fuzhitop=0;
optop=0;
}
int applyforitem(){return 1;}
void fuzhi_stack::fuzhi_push(item temp){
fzs[fuzhitop++]=temp;
// if(temp.x!=-1&&temp.x!=-2)
optop=fuzhitop-1;
}
void fuzhi_stack::fuzhi_pop(item &temp){
--fuzhitop;
--optop;
temp=fzs[fuzhitop];
}
int findfuzhibiao(int k){
switch(k){
case 43:return fuzhi_add;
case 45:return fuzhi_sub;
case 41:return fuzhi_mul;
case 48:return fuzhi_div;
case 51:return fuzhi_equ;
case 39:return fuzhi_leftkuohao;
case 40:return fuzhi_rightkuohao;
case 36:
case 37:return fuzhi_bc;
case fuzhi_end: return fuzhi_jing;
default :return -1;
}
}
void fuzhi_superpop(int i){
item temp[3];
switch(i){
case fuzhi_add :{
for(int j=0;j<3;j++)
FUZHI_STACK.fuzhi_pop(temp[j]);
FUZHI_STACK.optop++;
char tempc[templength];
tempc[0]='t';
tempc,itoa(c,tempc+1,10);
c++;
FUZHI_STACK.applyforitem(tempc);
item tempt(36,parse.list2.idend-1);
/////////////////////////////////////////
valuetype tempv;
int ttt=0;
if(temp[2].x==36)
ttt=VT.vt_findlocation(temp[2].y);
int kkk=0;
if(temp[0].y==36)
kkk=VT.vt_findlocation(temp[0].y);
if(ttt==-1||kkk==-1)error();
tempv.location=parse.list2.idend-1;
tempv.type=VT.vt[ttt].type;
VT.add(tempv);
///////////////////////////////////////////
FUZHI_STACK.fuzhi_push(tempt);
FUZHI_STACK.optop--;
FOMO.load(nowaddress,temp[1],temp[2],temp[0],tempt);
nowaddress++;
break;
}
case fuzhi_mul :{
for(int j=0;j<3;j++)
FUZHI_STACK.fuzhi_pop(temp[j]);
FUZHI_STACK.optop++;
char tempc[3];
tempc[0]='t';
tempc,itoa(c,tempc+1,10);
c++;
FUZHI_STACK.applyforitem(tempc);
item tempt(36,parse.list2.idend-1);
/////////////////////////////////////////
valuetype tempv;
int ttt=VT.vt_findlocation(temp[2].y);
tempv.location=parse.list2.idend-1;
tempv.type=VT.vt[ttt].type;
VT.add(tempv);
///////////////////////////////////////////
FUZHI_STACK.fuzhi_push(tempt);
FUZHI_STACK.optop--;
FOMO.load(nowaddress,temp[1],temp[2],temp[0],tempt);
nowaddress++;
break;
}
case fuzhi_div :{
for(int j=0;j<3;j++)
FUZHI_STACK.fuzhi_pop(temp[j]);
FUZHI_STACK.optop++;
char tempc[3];
tempc[0]='t';
tempc,itoa(c,tempc+1,10);
c++;
FUZHI_STACK.applyforitem(tempc);
item tempt(36,parse.list2.idend-1);
/////////////////////////////////////////
valuetype tempv;
int ttt=VT.vt_findlocation(temp[2].y);
tempv.location=parse.list2.idend-1;
tempv.type=VT.vt[ttt].type;
VT.add(tempv);
///////////////////////////////////////////
FUZHI_STACK.fuzhi_push(tempt);
FUZHI_STACK.optop--;
FOMO.load(nowaddress,temp[1],temp[2],temp[0],tempt);
nowaddress++;
break;
}
case fuzhi_equ:{
for(int j=0;j<3;j++)
FUZHI_STACK.fuzhi_pop(temp[j]);
FOMO.load(nowaddress,temp[1],temp[0],temp[0],temp[2]);
nowaddress++;
break;
}
case fuzhi_rightkuohao:{
for(int j=0;j<3;j++)
FUZHI_STACK.fuzhi_pop(temp[j]);
FUZHI_STACK.fuzhi_push(temp[1]);
break;
}
case fuzhi_bc :{
FUZHI_STACK.optop--;
break;
}
}///////switch
}
int fuzhi_stack::applyforitem(char fuhao[max3]){
parse.list2.add(fuhao);
return 1;
}
state fuzhi_E(){
FUZHI_STACK.fuzhi_clear();
state tempstate;
tempstate.codebegin=nowaddress;
tempstate.chain[0]=0;
item signtemp;
if(findfuhaobiao(sign.x)==-1)
error();
item tempitem(100,0);
FUZHI_STACK.fuzhi_push(tempitem);
// STACK.suanfutop++;
// STACK.optop++;
// int i=findfuhaobiao(STACK.sfs[STACK.optop].x);
int i;
int j=findfuzhibiao(sign.x);
for(;FUZHI_STACK.fuzhitop!=1||sign.x!=100;){
i=findfuzhibiao(FUZHI_STACK.fzs[FUZHI_STACK.optop].x);
if(i==-1||j==-1)error();
int k=fuzhibiao[i][j];
switch(k){
case 0:
case -1:{
FUZHI_STACK.fuzhi_push(sign);
getnextsign();
if((j=findfuzhibiao(sign.x))==-1){
signtemp=sign;
sign.x=100;
sign.y=0;
j=fuzhi_jing;
// sign=new jianzhi(100,0);
}
break;
}
case 1:{
fuzhi_superpop(i);
break;
}
default:error();
}//switch
}
sign=signtemp;
return tempstate;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -