编译原理实验报告 (8)

}

case 8:printf(\);t=8;break; case 9:printf(\);t=9;break; case 10:printf(\);t=10;break; case 11:printf(\);t=11;break; case 12:printf(\);t=12;break; case 13:printf(\);t=13;break; case 14:printf(\);t=14;break; case 15:printf(\);t=15;break; case 16:printf(\);t=16;break; case 17:printf(\);t=17;break; case 18:printf(\);t=18;break;

case 27:printf(\,FCON);return 27;break; case 28:printf(\);t=28;break; case 29:printf(\);t=29;break; case 30:printf(\);t=30;break; default : t=report_error(3); } return t;

break;

int scanner_example (FILE *fp) {

char ch; int i, c,t; lf=l;

ch=fgetc(fp); l+=1;

if (isalpha(ch)) /*it must be a identifer!*/ {

TOKEN[0]=ch; ch=fgetc(fp); l+=1; i=1;

while(isalnum(ch)) { }

TOKEN[i]='\\0'; c=lookup (TOKEN); if (c==0)

TOKEN[i]=ch; i++; ch=fgetc(fp); l+=1;

}

t=out (ID,TOKEN); t=out (c,\);

else

fseek(fp,-1,1); l-=1;

else if(isdigit(ch)||ch=='.'){ }

else switch(ch){ l+=1;

if(ch=='=')t=out(LE,\); else if(ch=='>') t=out (NE,\); else{ } break; break; l+=1; if(ch=='=') }

t=out(GE,\); fseek(fp,-1,1); l-=1;

t=out(GT,\); else{

fseek(fp,-1,1); l-=1;

t=out (LT,\); TOKEN[0]=ch; fseek(fp,-1,1); l-=1;

int k=LEX(fp); if(k==ClassF) { }

else if(UINT==k) { }

fseek(fp,-1,1); l-=1;

t=out(UINT,\); t=out(UFCON,\);

case '<': ch=fgetc(fp);

case '=': t=out(EQ, \); case '>': ch=fgetc(fp);

break; l+=1; if(ch=='=') }

break;

t=out(IS,\); fseek(fp,-1,1); t=report_error(2); l-=1; else {

case ':': t=ch=fgetc(fp);

case '+':t=out(ADD,\);break; case '-':t=out(SUB,\);break; case '*':t=out(MUL,\);break; case '/':t=out(DIV,\);break; case '(':t=out(LP,\);break; case ')':t=out(RP,\);break; case '#':t=out(EOI,\);break;

default: t=report_error(3); }

//************************************************语义分析**********

int IsVt(int a) { }

/*存储算符优先关系表,大于为,小于或等于为-1,其它为表示出*/ int changchartoint(FILE *fp) /*将字符转为数字,以得到算符优先值*/ {

int t; char ch; lf=l;

ch=fgetc(fp); coor(ch);

if(ch==EOF) t=20;

if(a==0||a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9)

return RIGHT; return ERROR; else break; }

return t;

}

while(ch!=EOF) { }

return t;

if(ch==' '||ch==9||ch==10){ } else{ }

fseek(fp,-1,1); l-=1;

switch(scanner_example(fp)){ case ADD:t=0;break; case SUB:t=1;break; case MUL:t=2;break; case DIV:t=3;break; case LP:t=4;break; case RP:t=5;break; case ID:t=6;break; case UINT:t=7;break; case UFCON:t=7;break; case IS:t=8;break; case EOI:t=9;break; case 10:t=10;break; }

ch=fgetc(fp); coor(ch);

if(ch==EOF) return 20;

break;

void changinttochar(int t){

switch(t){

case 0:printf(\);break; case 1:printf(\);break; case 2:printf(\);break; case 3:printf(\);break; case 4:printf(\);break; case 5:printf(\);break; case 6:printf(\);break; case 7:printf(\);break; case 8:printf(\);break; case 9:printf(\);break; case 10:printf(\);break; }

}

int parser (FILE *fp) {

int i, k, r, NewVn; /* NewVn holds left side of a production */ i=0; k=0; /* i, k is index of a[ ] and stack[ ] separately */ int sj; stack[0]=9; do {

int j;

if (IsVt(stack[k]))

j=k; j=k-1; else

printf(\中内容为(自底向上):\); for(sj=0;sj<=j;sj++)

changinttochar(stack[sj]); printf(\当前扫描字串为:\); r=changchartoint(fp); //a[i++]=r;

if(r==20&&stack[k]!=9)return report_error(8);

if(r>=0&&r<=3&&stack[k]>=0&&stack[k]<=3)return report_error(4);

//printf(\

while (IsHigherThan(stack[j],r)) {

int q; do {

NewVn=Reduce(j+1,k,r); for(sj=j+1;sj<=k;sj++)

stack[sj]=0;

k=j+1;/* reduce the leftmost prime phrase */

stack[k]=NewVn;/* it is stack[j+1] stack[j+2] ?stack[k] */ printf(\堆栈指针移动到k=%d\\n\,k);

q=stack[j];

if (IsVt(stack[j-1]))

j--; j-=2; else

}while(!IsLowerThan(stack[j],q));

} /*end of while*/


编译原理实验报告 (8).doc 将本文的Word文档下载到电脑

下一篇:自然地理

相关推荐
相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7 元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xxxxxx QQ:xxxxxx