}
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*/
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新综合文库编译原理实验报告 (8)全文阅读和word下载服务。
相关推荐: