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

資源簡介

編譯實驗,是對你在txt文檔中寫入的任意賦值語句程序段進行翻譯成四元式并且進行詞法分析。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
using?namespace?std;
typedef?struct?SqStack{//定義棧的數據結構??????
?char???*base;??????
????char???*top;??????
?}SqStack;????????????????????????????????
??struct?Query{//數據結點
char?thename[45];
};
struct?QueNode{//鏈表
Query?query;
QueNode?*pnext;
};
QueNode*Addshu(QueNode*phchar*str){
???QueNode*p1;
????p1=new?QueNode();
strcpy(p1->query.thenamestr);
????????p1->pnext=ph;
ph=p1;
return?ph;
}
void?Push(SqStack?&Schar?e){?//?將元素e插入到棧S中,成為新的棧頂元素???????
??*S.top++=e;
}????
??
char?Pop(SqStack?&Schar?&ch){?//字符型取棧頂元素并刪除之?????
????if(S.top==S.base){??????
????????ch=NULL;?????
????}??????
????else?ch=*--S.top;??????
?????return?ch;?
}??
?char?Gettop(SqStack?&Schar?&e){//字符型取棧頂元素
if(S.base==S.top)e=NULL;
?else?e=*(S.top-1);
return?e;
}
int?in(char?c){//判斷是否為運算符
??char?su[10]={‘+‘‘-‘‘*‘‘/‘‘(‘‘)‘‘;‘‘=‘};
?for(int?i=0;i<8;i++)
?if(c==su[i])return?1;
????return?0;
}
char?precede(char?x1char?x2){//優先級判斷
char?c1c2c;
c1=x1;c2=x2;
if(c1==‘(‘){
if(c2==‘)‘)
c=‘=‘;
else
c=‘<‘;
}
else?if(c1==‘)‘)
c=‘>‘;
else?if(c1==‘;‘){
?????????if(c2==‘;‘)
c=‘=‘;
else
c=‘<‘;
}
else{
int?ab;
????switch(c1){
???case?‘+‘:
???????case?‘-‘:a=2;break;
???????case?‘*‘:
???????case?‘/‘:a=3;break;
???????case?‘(‘:a=4;break;
???????????case?‘)‘:a=1;break;
???????case?‘;‘:a=-2;break;
???case?‘=‘:a=-1;break;
}
????switch(c2){?
???case?‘=‘:a=-1;break;
???????case?‘+‘:
???????case?‘-‘:b=2;break;
???????case?‘*‘:
???????case?‘/‘:b=3;break;
???????case?‘(‘:b=4;break;
???????case?‘)‘:b=1;break;
???????case?‘;‘:b=-2;break;
}
if(a-b>=0)c=‘>‘;
if(a-b<0)c=‘<‘;
}
return?c;
}
void?main(){
cout<<“賦值語句翻譯成四元式!!“<ifstream?fin(“thetwo.txt“);
ofstream?quedata(“answer.txt“);
char?cethetax;
char?a[20]=““b[20]=““;
int?s=0i=1;
char?chs[20]=““che[2]=““kon[20]=““;
QueNode*ph=NULL;
char?str[50];
????SqStack?stack;
????stack.base=stack.top=&str[0];?
Push(stack‘;‘);
????fin.get(c);
while(c!=‘;‘||Gettop(stacke)!=‘;‘){??
?if(!in(c)){?
??????che[0]=c;
????????if((c>=‘A‘&&c<=‘Z‘)||(c>=‘a‘&&c<=‘z‘)||c==‘_‘)i=0;
?strcat(chsche);fin.get(c);
if(in(c)){
??if(i==0)quedata<<“?“< ??else?quedata<<“?“< ph=Addshu(phchs);strcpy(chskon);
????????????if(c!=‘;‘)quedata<<“?“< else?quedata<<“?“< }
}
????else{
???char?a2=s+‘0‘;
char?a1[]={‘(‘‘t‘a2‘)‘‘\0‘};i=1;
??????? switch(precede(Gettop(stacke)c)){
case?‘<‘:
if(c==‘(‘||c==‘)‘)quedata<<“?“< Push(stackc);fin.get(c);break;
case?‘=‘:
x=Pop(stackx);fin.get(c);?break;
case?‘>‘:
theta=Pop(stacktheta);
strcpy(bph->query.thename);ph=ph->pnext;strcpy(aph->query.thename);ph=ph->

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????3595??2009-12-01?11:27??賦值語句的翻譯程序設計\賦值語句的翻譯程序設計.dsp

?????文件???????3424??2009-11-15?12:40??賦值語句的翻譯程序設計\賦值語句的翻譯程序設計.cpp

?????文件??????48640??2009-12-01?11:27??賦值語句的翻譯程序設計\賦值語句的翻譯程序設計.opt

?????文件????????552??2009-12-01?11:27??賦值語句的翻譯程序設計\賦值語句的翻譯程序設計.dsw

?????文件?????565336??2009-11-30?22:17??賦值語句的翻譯程序設計\Debug\賦值語句的翻譯程序設計.exe

?????文件??????41984??2009-12-01?11:27??賦值語句的翻譯程序設計\賦值語句的翻譯程序設計.ncb

?????文件????????278??2009-12-01?11:27??賦值語句的翻譯程序設計\賦值語句的翻譯程序設計.plg

?????文件?????????43??2009-11-15?12:35??賦值語句的翻譯程序設計\thetwo.txt

?????文件???????3026??2009-11-14?21:14??賦值語句的翻譯程序設計\themain.txt

?????文件????????922??2009-12-01?11:27??賦值語句的翻譯程序設計\answer.txt

?????目錄??????????0??2009-11-14?11:21??賦值語句的翻譯程序設計\Debug

?????目錄??????????0??2009-11-14?10:23??賦值語句的翻譯程序設計

-----------?---------??----------?-----??----

???????????????667800????????????????????12


評論

共有 條評論