?? jp jp(0).c
字號(hào):
strcpy(clh1->name,"");
clh1->type=record;
clh1->line[0]=getdq[0].line;
clh1->layer=-1;
clh1->layer=llayer;
clh->next=NULL;
switch(record)
{
case 1:if(getdq[0].t!=2)
{
free(clh1);
yfchc("","The type is unequal");/*記錄出錯(cuò)誤信息*/
return;
}
clh->a=atoi(getdq[0].name);
clh1->a=clh->a;
*cln=clh1;
fprintf(out,"\n%d%d",2,clh1);
getsy();/*重新讀入一個(gè)單詞到輸入棧*/
break;
case 2:fprintf(out,"\n%d%d",0,38);/*output '"'*/
getsy();/*重新讀入一個(gè)單詞到輸入棧*/
clh->c[0]='\0';
if(getdq[0].t==5)
{
strcpy(clh->c,getdq[0].name);
getsy();
}
if(getdq[0].t=='\0')
free(clh1);
else{
strcpy(clh->c,clh->c);
i=2;
while(getdq[0].t==5&&i<80&&doorkey<=3)
{
i=i+1;
strcpy(clh->c,getdq[0].name);
getsy();
}
*cln=clh1;
fprintf(out,"\n%d%d",2,clh1);
}
if(strcmp(getdq[0].name,"\"")==0)
{
fprintf(out,"\n%d%d",0,38);/*output '"'*/
getsy();/*重新讀入一個(gè)單詞到輸入棧*/
}
else{
yfchc("","Statemen missing'\"'");/*記錄出錯(cuò)誤信息*/
return;
}
break;
case 3:if(getdq[0].t!=4)
{
free(clh1);
yfchc("","The type is unequal");/*記錄出錯(cuò)誤信息*/
return;
}
clh->b=atoi(getdq[0].name);
clh1->b=clh->b;
*cln=clh1;
fprintf(out,"\n%d%d",2,clh1);
getsy();/*重新讀入一個(gè)單詞到輸入棧*/
}/*end switch*/
if(strcmp(getdq[0].name,",")==0)
{
fprintf(out,"\n%d%d",0,32);/*output ','*/
getsy();/*重新讀入一個(gè)單詞到輸入棧*/
}
else if(strcmp(getdq[0].name,";")==0)
{
fprintf(out,"\n%d%d",0,33);/*output ';'*/
getsy();/*重新讀入一個(gè)單詞到輸入棧*/
return;/*處理完畢,退出常量定義處理函數(shù)*/
}
else{
yfchc("","The type is unequal");/*記錄出錯(cuò)誤信息*/
return;/*常量定義出錯(cuò),退出常量定義處理函數(shù)*/
}
}/*end else 完成變量定義處理*/
}/*end if 變量名合法*/
else{
yfchc(getdq[0].name,"illegal name of variable");/*記錄出錯(cuò)誤信息*/
return;
}
}/*end while*/
}/*end cldy*/
int cfql(void) /*詞法處理程序,如果詞法分析通過,則返回1;否則返回0*/
{
int i=0,ii;
void *temp;
struct hsh *hshh;
struct cjbl *cjh;
struct bl *blh,**bln;
struct cl *clh,**cln;
struct shz *shzh,**shzn;
struct cch *cchh,**cchn;
/*printf("\n\n");
while(i<46)
{
printf(" %d%s",word[i],number,word[i].name);
i=i+1;
}
getch();*/
addr=0; /*全局變量初始化*/
fl=0;
ta=0;
hh=0;
doorkey=0;
in=fopen("aa.c","r");
out=fopen("aaa.c","w");
INPUT;
getsy();getsy();
getsy();
/*printf(" name hf line \n");
printf(".....................\n");
i=1;
while(feof(in)==0)
{i=i+1;
if(i==20)
{getch();i=1;printf("\n");}
getey();
printf("\n%15s%5d%5d",geted[0].name,getdy[0].t,getdy[0].line);
} */
head=malloc(sizeof(struct cjbl));/*初始化鏈表*/
head->layer=0;
head->a=NULL;
head->b=NULL;
head->c=NULL;
head->f=NULL;
head->next=NULL;
llayer=0;
while(doorkey<=3)
{
switch(getdq[0].t)
{
case 0:i=4;
temp=NULL;
hshh=NULL;
temp=set(-1,&i,getdq[0].name);
if(temp!=NULL)
{
if(strcmp(getdq[1].name,"(")==0)
{ ii=0;
hshh=temp;
while(ii<19&&hshh->line[ii]!=-1)
ii=ii+1;
if(ii<19)
{
hshh->line[ii]=getdq[0].line;
hshh->line[ii+1]=-1;
}
}
}
i=6;
temp=NULL;
temp=set(0,&i,getdq[0].name);
if(temp!=NULL)
{
ii=0;
cchh=temp;
while(ii<19&&hshh->line[ii]!=-1)
ii=ii+1;
if(ii<19)
{
cchh->line[ii]=getdq[0].line;
cchh->line[ii+1]=-1;
}
if(hshh!=NULL)
fprintf(out,"\n%d%d",4,hshh);
else fprintf(out,"\n%d%d",6,cchh);
getsy();
break;
}
fprintf(out,"\n%d%d",6,yfchc(getdq[0].name,"illeal word"));
getsy();
break;
case 1:i=chjtb(getdq[0].name);
if(i>6&&i<14)/*在靜態(tài)表中找到*/
{
fprintf(out,"\n%d%d",0,i); /*output 保留字代碼*/
getsy();
}
else
if(i<5&&i>0)
if(strcmp(getdq[2].name,"(")==0)
; /* hshdy(i);*/
else{
if(i>0&&i<4)
bldy(i);
else
{ fprintf(out,"\n%d%d",0,i);
getsy();
}
}
else if(i==5)
cldy();/*此處是常量處理函數(shù)*/
if(i==0) /*在靜態(tài)表中找不到*/
{
i=4;
temp=NULL;
temp=set(-1,&i,getdq[0].name);
if(temp!=NULL)
{
if(strcmp(getdq[1].name,"(")==0)
{ ii=0;
hshh=temp;
while(ii<19&&hshh->line[ii]!=-1)
ii=ii+1;
if(ii<19)
{
hshh->line[ii]=getdq[0].line;
hshh->line[ii+1]=-1;
}
fprintf(out,"\n%d%d",4,hshh);
getsy();
break;
}
}
i=0;
temp=set(llayer,&i,getdq[0].name);
if(temp==NULL)
temp=set(0,&i,getdq[0].name);
if(temp==NULL)
{
fprintf(out,"\n%d%d",6,yfchc(getdq[0].name,"undefined word"));
getsy();
}
else{
switch(i)
{
case 1:blh=temp;
ii=0;
while(ii<19&&blh->line[ii]!=-1)
ii=ii+1;
if(ii<19)
{
blh->line[ii]=getdq[0].line;
blh->line[ii+1]=-1;
}
fprintf(out,"\n%d%d",i,blh);
getsy();
break;
case 2: clh=temp;
ii=0;
while(ii<19&&clh->line[ii]!=-1)
ii=ii+1;
if(ii<19){
clh->line[ii]=getdq[0].line;
clh->line[ii+1]=-1;
}
fprintf(out,"\n%d %d",i,clh);/*output define word*/
getsy();
break;
case 3:shzh=temp;
ii=0;
while(ii<19&&shzh->line[ii]!=-1)
ii=ii+1;
if(ii<19)
{
shzh->line[ii]=getdq[0].line;
shzh->line[ii+1]=-1;
}
fprintf(out,"\n%d %d",i,shzh);
getsy();
break;
case 6:cchh=temp;
ii=0;
while(ii<19&&cchh->line[ii]!=-1)
ii=ii+1;
if(ii<19)
{
cchh->line[ii]=getdq[0].line;
cchh->line[ii+1]=-1;
}
fprintf(out,"\n%d %d",i,cchh);
getsy();
}/*end switch*/
}
}
break;
case 2:clh=malloc(sizeof(struct cl));
i=2;
cln=set(llayer,&i,"");
*cln=clh;
strcpy(clh->name,"");
clh->type=1;
clh->a=atoi(getdq[0].name);
clh->line[0]=getdq[0].line;
clh->line[1]=-1;
clh->layer=llayer;
clh->next=NULL;
fprintf(out,"\n%d %d",2,clh);
getsy();
break;
case 3:i=chjtb(getdq[0].name);
if(i==0)
{
fprintf(out,"\n%d %d",6,yfchc(getdq[0].name,"illegal word"));
getsy();
}
else{
fprintf(out,"\n%d %d",0,i);
getsy();
}
break;
case 4: clh=malloc(sizeof(struct cl));
i=2;
cln=set(llayer,&i,"");
*cln=clh;
strcpy(clh->name,"");
clh->type=3;
clh->b=atof(getdq[0].name);
clh->line[0]=getdq[0].line;
clh->line[1]=-1;
clh->layer=llayer;
clh->next=NULL;
fprintf(out,"\n%d %d",2,clh);
getsy();
break;
case 5:clh=malloc(sizeof(struct cl));
i=2;
cln=set(llayer,&i," ");
*cln=clh;
strcpy(clh->name," ");
clh->type=2;
clh->line[0]=getdq[0].line;
clh->line[1]=-1;
clh->c[0]='\0';
i=1;
while(getdq[0].t==5&&i<80&&doorkey<=3){
i=i+1;
strcat(clh->c,getdq[0].name);
getsy();
}
clh->layer=llayer;
clh->next=NULL;
fprintf(out,"\n%d %d",2,clh);
break;
}/*end switch*/
}/*end while*/
fclose(in);
fclose(out);
if(head->f==NULL)
return(1);
else{
ii=1;
cchh=head->f;
printf("\n\n\n");
while(cchh!=NULL&&ii<=10){
printf("\n Foundq errot at ");
i=0;
while(cchh->line[i]!=-1)
{
printf("%d",cchh->line[i]);
if(cchh->line[i+1]==-1)
printf(" : ");
else printf(" , ");
i=i+1;
}/*end while(pp.f->line[i]!=-1)*/
if(strlen(cchh->name)!=0)
printf("'%s' is ",cchh->name);
printf("%s",cchh->why);
cchh=cchh->next;
if(ii==10)
{
ii=1;
printf("\n Press any key to continue.");
getch();
printf("\n");
}
ii=ii+1;
}/*end while(cchh!=NULL&&ii<=10)*/
return(0);
}
}
void freenode(void)/*free the node*/
{
union all
{
struct bl *a;/*1*/
struct cl *b;/*2*/
struct shz *c;/*3*/
struct cjbl *e;/*5*/
struct cch *f;/*6*/
}pp,ll;
struct hsh * hshh,* hshf;
if(head->a!=NULL)
{
pp.a=head->a;
while(pp.a!=NULL)
{
ll.a=pp.a;
pp.a=pp.a->next;
free(ll.a);
}
}/*end if(a)*/
if(head->b!=NULL)
{
pp.b=head->b;
while(pp.b!=NULL)
{
ll.b=pp.b;
pp.b=pp.b->next;
free(ll.b);
}
}/*end if(b)*/
if(head->c!=NULL)
{
pp.c=head->c;
while(pp.c!=NULL)
{
ll.c=pp.c;
pp.c=pp.c->next;
free(ll.c);
}
}/*end if(c)*/
if(head->f!=NULL)
{
pp.f=head->f;
while(pp.f!=NULL)
{
ll.f=pp.f;
pp.f=pp.f->next;
free(ll.f);
}
}/*end if(f)*/
hshh=head->next;
free(head);
while(hshh!=NULL)
{
if(head->a!=NULL)
{
pp.a=head->a;
while(pp.a!=NULL)
{
ll.a=pp.a;
pp.a=pp.a->next;
free(ll.a);
}
}/*end if(a)*/
if(head->b!=NULL)
{
pp.b=head->b;
while(pp.b!=NULL)
{
ll.b=pp.b;
pp.b=pp.b->next;
free(ll.b);
}
}/*end if(b)*/
if(head->c!=NULL)
{
pp.c=head->c;
while(pp.c!=NULL)
{
ll.c=pp.c;
pp.c=pp.c->next;
free(ll.c);
}
}/*end if(c)*/
hshf=hshh;
hshh=hshh->next;
free(hshf);
}/*end while(hshh!=NULL)*/
}/*end freenode(void)*/
int cffx(void){
char c;
while(1){
if(cfql()==1)
{
printf("\n\n You are success!");
getch();
return(1);
}
else{
printf("\n Do you want to compile again! y/n");
while((c=getch())!='y'&&c!='n');
if(c=='n')return(0);
else freenode();
}
}
}
void main()/*the main programe*/
{
cffx();
out=fopen("aaa.c","w");
testpro();
fclose(out);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -