📄 llfenxi.cpp
字号:
// LlFenxi.cpp: implementation of the LlFenxi class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "bianyi.h"
#include "LlFenxi.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LlFenxi::LlFenxi()
{
diji=0;
}
LlFenxi::~LlFenxi()
{
}
void LlFenxi::bachpath(int n,int m)
{
StrOper1 stroper;
vector<string>::iterator iter=four.begin();
for(int i=0;i<n;i++)
{
iter++;
}
string sbuf1=*iter+stroper.inttostr(m);
*iter=sbuf1;
}
void LlFenxi::listoutv(vector<string> s)
{
vector<string>::iterator it=s.begin();
for(int i=1;i<=s.size();i++)
{
cout<<*it<<endl;
it++;
}
}
void LlFenxi::huitian()
{
bachpath(f1out,f3in);
bachpath(f3out1,f4in);
bachpath(f3out2,zuihou);
bachpath(f4out,f2in);
}
int LlFenxi::findchar(char a)
{
char yigui[]={'d','u','s','f','i','r','(',')','#'};
for(int i=0;i<=8;i++)
{
if(a==yigui[i])
return i;
}
}
int LlFenxi::findno(string a)
{
string yigui[]={"S","A","B","C","K","E","D"};
for(int i=0;i<=6;i++)
{
if(a==yigui[i])
return i;
}
if(a=="#")
{
return -2;
}
else
return -1;
}
void LlFenxi::pushstr(string s)
{
StrOper1 stroper;
if(s!="$")
{
int len=s.length()-1;
char *buf=(char *)s.c_str();
for(int i=len;i>=0;i--)
{
sta.push(stroper.chartstr(buf[i]));
}
}
else
{
}
}
int LlFenxi::fenxi(char *in,FILE *file,danci *w)
{
bian=w[1].key;
string rules[]={"AdK","BuE","CsE","fK","i=E","(E)D","iD","rED","$"};
fxlist ag[7][9]={
{{0,0},{0,0},{0,0},{1,0},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{1,1},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{1,2},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{1,3},{0,0},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{0,0},{1,4},{0,0},{0,0},{0,0},{0,0}},
{{0,0},{0,0},{0,0},{0,0},{1,6},{0,0},{1,5},{0,0},{0,0}},
{{1,8},{1,8},{1,8},{0,0},{0,0},{1,7},{0,0},{1,8},{1,8}}
};
StrOper1 stroper;
sta.push("#");
sta.push("S");
int ji=0;
int mid=0;
int len=strlen(in);
while(ji<=len)
{
char a=stroper.getone(in);
string nod=sta.top();
const char *kbuf=nod.c_str();
string sbuf;
if(isdigit(kbuf[0]))
{
if(nod=="3")
{
cout<<diji;
string sbuf=stroper.inttostr(diji)+":goto ";
four.push_back(sbuf);
cout<<"goto"<<endl;
f1out=diji;
diji++;
f2in=diji;
}
else if(nod=="2")
{
string va1=value.top();
value.pop();
cout<<diji;
cout<<"i=i+"<<va1<<endl;
sbuf=stroper.inttostr(diji)+":"+bian+"="+bian+"+"+va1;
four.push_back(sbuf);
diji++;
f3in=diji;
}
else if(nod=="1")
{
string va1=value.top();
value.pop();
cout<<diji;
cout<<"if i<"+va1+"goto"<<endl;
sbuf=stroper.inttostr(diji)+":if "+bian+"<="+va1+" goto ";
four.push_back(sbuf);
f3out1=diji;
diji++;
cout<<diji;
cout<<"goto"<<endl;
sbuf=stroper.inttostr(diji)+":goto ";
four.push_back(sbuf);
f3out2=diji;
diji++;
f4in=diji;
}
else if(nod=="0")
{
cout<<diji;
cout<<"goto"<<endl;
sbuf=stroper.inttostr(diji)+":goto ";
four.push_back(sbuf);
f4out=diji;
diji++;
zuihou=diji;
sbuf=stroper.inttostr(diji)+":";
four.push_back(sbuf);
}
else if(nod=="7")
{
string va1=value.top();
value.pop();
string va2=value.top();
value.pop();
string kbuf1="t"+stroper.inttostr(mid);
value.push(kbuf1);
mid++;
cout<<diji;
cout<<"i="+va1+"+"<<va2<<endl;
sbuf=stroper.inttostr(diji)+":"+kbuf1+"="+va1+"+"+va2;
four.push_back(sbuf);
diji++;
}
else if(nod=="4")
{
string va1=value.top();
value.pop();
string va2=value.top();
value.pop();
cout<<diji;
cout<<va2+"="<<va1<<endl;
sbuf=stroper.inttostr(diji)+":"+va2+"="+va1;
four.push_back(sbuf);
diji++;
}
sta.pop();
}
else
{
if(findno(nod)==-1)
{
if(nod==stroper.chartstr(a))
{
if(a=='i')
{
value.push(w[ji].key);
}
stroper.read(in);
sta.pop();
ji++;
continue;
}
else
{
cout<<"error"<<endl;
exit(1);
}
}
else
{
if(nod=="#")
{
if(stroper.chartstr(a)==nod)
{
cout<<"sucess"<<endl;
huitian();
listoutv(four);
return 1;
}
else
{
cout<<"error"<<endl;
return 0;
}
}
else
{
int i,j;
j=findchar(a);
i=findno(sta.top());
if(ag[i][j].kind==0)
{
cout<<"error"<<endl;
return 0;
}
else
{
sta.pop();
int intbuf=ag[i][j].key;
sta.push(stroper.inttostr(intbuf));
pushstr(rules[ag[i][j].key]);
}
}
}
}
}
}
void LlFenxi::vwfile(FILE *file,vector<string> s)
{
vector<string>::iterator it=s.begin();
StrOper1 stroper;
string sbuf;
for(int i=1;i<=s.size();i++)
{
sbuf=(*it)+"\r\n";
fputs(sbuf.c_str(),file);
it++;
}
}
int LlFenxi::zong(char *a,FILE *file,danci *w)
{
int i=fenxi(a,file,w);
if(i==1)
{
vwfile(file,four);
return 1;
}
else
{
char *kbuf="error";
fputs(kbuf,file);
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -