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

  • 大小: 424KB
    文件類型: .rar
    金幣: 2
    下載: 2 次
    發布日期: 2021-06-05
  • 語言: 其他
  • 標簽: 編譯原理??

資源簡介

基于語法制導翻譯的表達式轉換編譯器 中綴表達式轉后綴表達式,含文檔。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include?
#include“t_node.h“
using?namespace?std;

?//判斷c是否是操作符
bool?judge(char?c);

//在c中下標在first和last之間的最小元素的下標
int??findmin(vector?cint?firstint?last);??

//?把輸入的表達式字符竄進行處理,把每個操作數和操作符依次保存在b中,在c中保存相應分優先級

void?translate(string?avector?&bvector?&cint?*flag2);?

//轉變成表達式數
void?trantotree(vector?bvector?ct_node?*root);

//進行后序遍歷
void?search(t_node?*root);

//清除該樹占用的內存
void?deletetree(t_node?*root);

int?main()
{
string?s;
char?c;
int?flag=1;
int?*flag2;
????while(flag==1){
????*flag2=1;
????vector?v1;
vector?v2;
t_node?*root=new?t_node();?
cout<<“請輸入中綴表達式:“<????cin>>s;
translate(sv1v2flag2);
while(*flag2==1){
????trantotree(v1v2root);
cout<<“后序遍歷結果為:“< search(root);
cout< deletetree(root);
break;
}
cout<<“是不是要繼續(y/n)?“<????cin>>c;
????if?(c?==?‘n‘?||?c?==?‘N‘)?flag?=?0;?
????while?(getchar()?!=?‘\n‘);?
????printf(“\n“);?
????continue;
}
}



void?deletetree(t_node?*root)
{
if(root!=NULL)
{
deletetree(root->left);
????????deletetree(root->right);
delete?root;
}

}


void?search(t_node?*root)
{
if(root!=NULL)
{
search(root->left);
search(root->right);
cout<value<<“?“;
}

}

int?rank(char?ch)
{
if(ch==‘+‘||ch==‘-‘)
return?1;
else?if(ch==‘*‘||ch==‘/‘||ch==‘%‘)
return?100;
else
return?1000;


}

bool?judge(char?c)
{
if(c==‘+‘||c==‘-‘||c==‘*‘||c==‘/‘||c==‘%‘)
return?true;
else?
return?false;
}


int?findmin(const?vector?cint?firstint?last)
{
int?temp=c[last]k=last;
for(int?i=last-1;i>=first;i--)
{
if(c[i] {
k=i;
temp=c[k];
}
}
return?k;
}

//轉變成表達式數
void?trantotree(vector?bvector?ct_node?*root)
{
if(b.size()==1)
root->value=b[0];


???else
???{
???vector?b1b2;
???vector?c1c2;
???int?ij;
???i=findmin(c0c.size()-1);
???????root->value=b[i];
???for(j=0;j ???{
???b2.push_back(b[j]);
???c2.push_back(c[j]);
???}
???root->left=new?t_node();
???????trantotree(b2c2root->left);
???for(j=i+1;j ???{
???b1.push_back(b[j]);
???????c1.push_back(c[j]);
???}
???????root->right=new?t_node();
???????trantotree(b1c1root->right);
???}


}

//?把輸入的表達式字符竄進行處理,把每個操作數和操作符依次保存在b中,在c中保存相應分優先級
void?translate(string?avector?&bvector?&cint?*flag2)
{
int?len=a.length();
int?i=0j=0k=0count=0count1=0count2=0;
string?s=““;
while(i {
if(a[i]==‘(‘)
{
k++;
i++;
count++;
count1++;?
continue;
}

if(a[i]==‘)‘)
{
k--;
i++;
count--;
count2++;?
continue;
}
if(count2>count1){cout<<“輸入的表達式不正確!右括號在前!“?<????????if(!judge(a[i]))//a[i]不是運算符!?
{
s=s+a[i];
i++;
}
????????else????????????//a[i]是運算符!?
{
if(ju

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

?????文件???????3718??2010-06-29?11:17??編譯原理\main.cpp

?????文件?????243656??2010-06-29?18:16??編譯原理\main.o

?????文件????????998??2010-06-29?22:58??編譯原理\Makefile.win

?????文件?????167974??2010-06-30?09:22??編譯原理\tempfile.exe

?????文件??????28664??2010-06-30?22:47??編譯原理\tempfile.rar

?????文件????????413??2010-06-29?11:17??編譯原理\t_node.cpp

?????文件????????594??2009-04-26?00:59??編譯原理\t_node.h

?????文件??????59060??2010-06-29?18:16??編譯原理\t_node.o

?????文件???????1032??2010-06-29?17:23??編譯原理\中綴式變后綴式.dev

?????文件?????716008??2010-06-29?22:58??編譯原理\中綴式變后綴式.exe

?????文件?????320000??2010-07-01?12:27??編譯原理\編譯原理文檔111--楊博.doc

?????目錄??????????0??2010-07-01?12:27??編譯原理

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

??????????????1542117????????????????????12


評論

共有 條評論