布尔表达式的翻译程序设计 - 百度文库 ر

}

}

scaner(); B();

void interpreter::B() { }

void interpreter::B1() {

if

t[tcount].emit(\tcount++; T(); B1();

(strcmp(token,rwtab[8])==0){t[tcount].emit(\t++;scaner();T();B1();scaner();} }

void interpreter::T() { }

void interpreter::T1() {

else t[tcount].emit(\

t[tcount].emit(\tcount++; F(); T1();

13

if

(strcmp(token,rwtab[7])==0){t[tcount].emit(\t++;scaner();F();T1();} }

// F not F |truefalse |B| i rop i void interpreter::F() {

if(strcmp(token,rwtab[1])==0){t[tcount].emit(\

else t[tcount].emit(\

ount++;scaner();F();}

else

if(strcmp(token,rwtab[0])==0){t[tcount].emit(\++;scaner();}

else

if(strcmp(token,rwtab[2])==0)

{t[tcount].emit(\

else

if(strcmp(token,rwtab[3])==0){t[tcount].emit(\+;scaner();B();}

else

if(strcmp(token,rwtab[6])==0){t[tcount].emit(\t++;scaner();scaner();scaner();} }

void interpreter::scaner() {

int m=0;

for(int i=0;i<8;i++) token[i]=' ';

while (buffercode[current]==' ') current++;

if(((buffercode[current]>='a')&&(buffercode[current]<='z'))||((bu

14

ffercode[current]>='A')&&(buffercode[current]<='Z')))

{

while

((((buffercode[current]>='a')&&(buffercode[current]<='z'))||((buffercode[current]>='A')&&(buffercode[current]<='Z')))||((buffercode[current]>='0')&&(buffercode[current]<='9')))

} else

if

(buffercode[current]=='(')

{ }

token[m++]='\\0';

token[m]=buffercode[current];m++; current++;

{token[0]='(';token[1]='\\0';current++;}

else

if

(buffercode[current]==')')

{token[0]=')';token[1]='\\0';current++;} }

char*interpreter::expression() {

char *tp,*ep2,*eplace,*tt; tp=new char[8]; ep2=new char[8]; eplace=new char[8]; tt=new char[8]; strcpy(eplace,term()); while(strcmp(token,\{

strcpy(tt,token);

15

scaner();

strcpy(ep2,term()); strcpy(tp,newtemp()); qemit(tp,eplace,tt,ep2); strcpy(eplace,tp);

}

return eplace;

}

char*interpreter::term() { char *tp,*ep2,*eplace,*tt; tp=new char[8]; ep2=new char[8]; eplace=new char[8]; tt=new char[8]; strcpy(eplace,unit());

while (strcmp(token,\ { strcpy(tt,token); scaner();

strcpy(ep2,unit()); strcpy(tp,newtemp()); qemit(tp,eplace,tt,ep2); strcpy(eplace,tp);

}

// scaner(); return eplace;

}

char* interpreter::unit()

16