⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jp jp(0).c

📁 是词法分析程序,可以对词法分析有更深的了解与认识
💻 C
📖 第 1 页 / 共 3 页
字号:
          clh->line[0]=getdq[0].line;
          clh->line[1]=-1;
          clh->layer=llayer;
          clh->next=NULL;/* fill over the const form,and the deal with const var node*/
                  fprintf(out,"\n%d %d",2,clh);/*output length*/
                  getsy();/*重新读入一个章词到输入栈*/
                  }/*end if,deal the length over*/
          else{/*if the length value is not a digtal,then*/
            shzh->length=-1;/*define arrays error*/
            shzh->start=-1;
            yfchc(" ","illegal length of array");
            return;
                   }
        if(strcmp(getdq[0].name,"]")==0)
        {
            fprintf(out,"\n%d %d",0,28);/*output ']'*/
            getsy();/*重新读入一个章词到输入栈*/
        }
        else{
            yfchc(" ","Statement missing']'");
            return;
            }
        if(strcmp(getdq[0].name,",")==0){
            fprintf(out,"\n%d %d",0,32);/*output ','*/
            getsy();/*重新读入一个章词到输入栈*/
            }
            else if(strcmp(getdq[0].name,";")==0)
                {
                 fprintf(out,"\n%d %d",0,33);/*output ';'*/
                 getsy();/*重新读入一个章词到输入栈*/
                return;/*over*/
                }
                else{
                       yfchc(" ","Statement missing ','or';'");
                    return;
                    }
                }/*end if,define array over*/
                

        else{/*deal with the var*/
                blh=malloc(sizeof(struct bl));
                style=1;
                bln=set(llayer,&style," ");
                *bln=blh;
                strcpy(blh->name,getdq[0].name);
                blh->type=record;
                blh->line[0]=getdq[0].line;
                blh->line[1]=-1;
                blh->layer=llayer;
                blh->start=addr;
                switch(record)/*count the next var`s began address*/
                {
                  case 1:addr=addr+2;break;
                  case 2:addr=addr+1;break;
                  case 3:addr=addr+4;break;
                    }/*end switch*/
            blh->next=NULL;/*fill var form over,deal the var node over*/
            fprintf(out,"\n%d %d",1,blh);/*output var name*/
            getsy();/*重新读入一个章词到输入栈*/
            if(strcmp(getdq[0].name,",")==0)
            {
            fprintf(out,"\n%d %d",0,32);/*output ','*/
            getsy();/*重新读入一个章词到输入栈*/
            }
            else if(strcmp(getdq[0].name,";")==0)
                {
                fprintf(out,"\n%d %d",0,33);/*output ','*/
                getsy();/*重新读入一个章词到输入栈*/
                return;/*deal over and exit*/
                }
                else{
                    yfchc(" ","Statement missing ',' or ';'");
                    return;
                    }
                }/*end else ,over deal the var*/
            }/*deal over one var*/
         else{
                yfchc(getdq[0].name,"illegal name of variable");
                return;
            }
        }/*end while*/
    }


    void testpro(void){
    int type,num;
    int i;
    int door,doorskip=0;
    char c;
    union all   
        {
                        struct bl *a;/*1*/
                        struct cl *b;/*2*/
                        struct shz *c;/*3*/
                        struct hsh *d;
                        struct cjbl *e;/*5*/
                        struct cch *f;/*6*/
            }pp,ll;

      printf("\n\n\n");
      printf("\n Now,the cffx() programe have finished,");
      printf("\nand all words of source program have been analyzed!");
      printf("\n\n Press 's' to skip,or press other any key will show the message of one word...");

      if(getch()=='s') doorskip=1;
door=1;
while(door>1)
{
  if(door==1&&(feof(out)!=0||doorskip==1))
    {
     printf("\n\n Press'e'to exit,or press'y' enter chain-table.");
      while((c=getch())!='e'&&c!='y');
       if(c=='e')
        break;
      else door=2;
    }
if(door==1&&feof(out)==0)
   fscanf(out,"%d %d",&type,&num);
if(door==2)
   {
       printf("\n\n Please input your choic:\n Press'h'enter head-node;");
       printf("press'e'to exit !");
       printf("\n press'n'enter next node:");
       printf("Press'a'to go to the address you input.");
  while((c=getch())!='h'&&c!='n'&&c!='a'&&c!='e');
    switch(c)
   {
    case 'h':type=5;
          num=(int)head;
           break;
   case 'n':switch(type)
          {
           case 11:type=1;
           case 1:pp.a=(struct bl*)num;
                 if(pp.a->next!=NULL)
                 num=(int)pp.a->next;
                   else{
                    printf("\n\n The next node is NULL! press any key to continue.");
                       getch();
                         type=11;
                       }
                      break;
          case 12:type=2;
           case 2:pp.b=(struct cl *)num;
               if(pp.b->next!=NULL)
               num=(int)pp.b->next;
               else{
                  printf("\n\n the next node is NULL! Press any key to continue.");
                 getch();
                   type=12;
              }
              break;
case 13:type=3;
case 3:pp.c=(struct shz *)num;
if(pp.c->next!=NULL)
num=(int)pp.c->next;
else{
printf("\n\n the next node is NULL! Press any key to continue.");
getch();
type=13;
}
break;
case 14:type=4;
case 4:pp.d=(struct hsh *)num;
if(pp.d->next!=NULL)
num=(int)pp.d->next;
else{
printf("\n\n the next node is NULL! Press any key to continue.");
getch();
type=14;
}
break;
case 15:type=5;
case 5:pp.e=(struct cjbl *)num;
if(pp.e->next!=NULL)
{
num=(int)pp.e->next;
type=4;
}
else{
printf("\n\n the next node is NULL! Press any key to continue.");
getch();
type=15;
}
break;
case 16:type=6;
case 6:pp.f=(struct cch *)num;
if(pp.f->next!=NULL)
num=(int)pp.f->next;
else{
printf("\n\n the next node is NULL! Press any key to continue.");
getch();
type=16;
}
}/*end switch(type)*/
break; 
case 'a':printf("\n\n Please input your address and number of struct.");
printf("\n The address=");
scanf("%d",&num);
printf("The number=");
scanf("%d",&type);
break;
case 'e':return;
}/*end switch(c)*/
}/*end if(door==2)*/
switch(type)
{
case 0:printf("\n\n%d&d",type,num);
printf("        %s",word[num].name);
break;
case 7:printf("\n\n%d&d",type,num);
break;
case 1:printf("\n\n%d&d",type,num);
pp.a=(struct bl*)num;
printf("\n       name=%s",pp.a->name);
printf("\n       type=%d",pp.a->type);
printf("\n       start=%d",pp.a->start);
printf("\n       layer=%d",pp.a->layer);
i=0;
printf("\n       line=");
while(pp.a->line[i]!=1)
{
printf("%d,",pp.a->line[i]);
i=i+1;
}
printf("\n           next=%d,",pp.a->next);
break;
case 2:printf("\n\n%d&d",type,num);
pp.b=(struct cl*)num;
printf("\n       name=%s",pp.b->name);
printf("\n       type=%d",pp.b->type);
printf("\n       layer=%d",pp.b->layer);
 switch(pp.b->type)
{
case 1:printf("\n          int=%d",pp.b->a);
break;
case 2:printf("\n          int=%s",pp.b->c);
break;
case 3:printf("\n          int=%f",pp.b->b);
}
i=0;
printf("\n       line=");
while(pp.b->line[i]!=-1)
{
printf("%d,",pp.b->line[i]);
i=i+1;
}
printf("\n           next=%d,",pp.b->next);
break;
case 3:printf("\n\n%d&d",type,num);
pp.c=(struct shz*)num;
printf("\n       name=%s",pp.c->name);
printf("\n       type=%d",pp.c->type);
printf("\n       start=%d",pp.c->layer);
printf("\n        layer=%d",pp.c->layer);
printf("\n        length=%d",pp.c->length);
i=0;
printf("\n       line=");
while(pp.c->line[i]!=-1)
{
printf("%d,",pp.c->line[i]);
i=i+1;
}
printf("\n           next=%d,",pp.c->next);
break;
case 4:printf("\n\n%d&d",type,num);
pp.d=(struct hsh*)num;
printf("\n       name=%s",pp.d->name);
printf("\n       type=%d",pp.d->type);
printf("\n        layer=%d",pp.d->layer);
i=0;
printf("\n       line=");
{
printf("%d,",pp.c->line[i]);
i=i+1;
}
printf("\n           struct b1*a =%d,",pp.d->a);
printf("\n           struct c1*b=%d,",pp.d->b);
printf("\n           struct shz*c=%d,",pp.d->c);
i=0;
printf("\n           csh[5].p=    ");
while(i<5&&pp.d->csh[i].p!=NULL)
{
printf("%-7d",pp.d->csh[i].p);
i=i+1;
}
i=0; 
printf("\n           csh[5].style");
while(i<5&&pp.d->csh[i].p!=NULL)
{
printf("%-7d",pp.d->csh[i].style);
i=i+1;
}
printf("\n           next=%d,",pp.d->next);
break;
case 5:printf("\n\n%d&d",type,num);
pp.e=(struct cjbl*)num;
printf("\n       name=%d",pp.e->layer);
printf("\n           struct b1*a =%d,",pp.e->a);
printf("\n           struct c1*b =%d,",pp.e->b);
printf("\n           struct shz*c =%d,",pp.e->c);
printf("\n           struct cch*f =%d,",pp.e->f);
printf("\n           next=%d",pp.e->next);
break;
case 6:printf("\n\n%d&d",type,num);
pp.f=(struct cch*)num;
printf("\n       name=%s",pp.f->name);
printf("\n        layer=%d",pp.f->layer);
printf("\n        why=%s",pp.f->why);
i=0;
printf("\n       line=");
{
printf("%d,",pp.c->line[i]);
i=i+1;
}
printf("\n          next=%d",pp.f->next);
}/*end switch */
if(door==1)
getch();
}/*end switch */
}/*end testpro */














void cldy(void)
{
int i;
int record,typee,style;
struct cl *clh,*clh1,**cln;
fprintf(out,"\n%d %d",0,5);/*输出"const" */
getsy();
while(1)/*进入常量处理 */
{
record=0;
typee=chjtb(getdq[0].name);
if(typee==1||typee==2||typee==3)/*单词为合法的变量类型 */
{
record=typee;/*记下变量的类型*/
fprintf(out,"\n%d%d",0,typee);/*output 变量类型 */
getsy();/*重新读入一个单词到输入栈*/
typee=chjtb(getdq[0].name);
}
else{
yfchc("","declaration stntax error");/*记录出错误信息*/
return;/*常量定义出错,退出常量定义处理函数*/
}
if(record!=0&&getdq[0].t==1&&typee==0)/*定义的变量名合法*/
{
if(chjtb(getdq[1].name)==27)/*确定为数组定义,27号表示'['*/
{
if(record!=2)
{
yfchc("","Sorry,only char array is legal in const definition");/*记录出错误信息*/
return;  /*在常量定义中仅支持字符数组,如不是,退出常量定义处理函数*/
}
clh=malloc(sizeof(struct cl));/*申请一个常量节点,并连接*/
style=2;
cln=set(llayer,&style,"");
*cln=clh;
strcpy(clh->name,getdq[0].name);
clh->type=2;
clh->c[0]='\0';
clh->line[0]=getdq[0].line;
clh->line[1]=-1;
clh->layer=llayer;
clh->next=NULL;/*填完部分常量表,但是内容没填*/
fprintf(out,"\n%d%d",2,clh);/*output 常量名*/
getsy();/*重新读入一个单词到输入栈*/
fprintf(out,"\n%d%d",0,27);/*output '['*/
getsy();/*重新读入一个单词到输入栈*/
if(getdq[0].t==2)/*如果是数字,则长度有效*/
{
clh1=malloc(sizeof(struct cl));/*申请一个常量节点,并连接*/
style=2;
cln=set(llayer,&style,"");
*cln=clh1;
strcpy(clh1->name,"");
clh1->type=1;
clh1->a=atoi(getdq[0].name);
clh1->line[0]=getdq[0].line;
clh1->layer=-1;
clh1->layer=llayer;
clh->next=NULL;/*填完部分常量表,但是内容没填*/
fprintf(out,"\n%d%d",2,clh1);/*output 常量名*/
getsy();/*重新读入一个单词到输入栈*/
}/* end if,长度处理完毕*/
else/*如果长度值不是数字,则进行以下处理*/
{
clh->c[0]='\0';
yfchc("","illegal length of array");/*记录出错误信息*/
return;/*数组的定义不合法,退出常量定义处理函数*/
}
if(strcmp(getdq[0].name,"]")==0) 
{
fprintf(out,"\n%d%d",0,28);/*output ']'*/
getsy();/*重新读入一个单词到输入栈*/
}
else{ 
yfchc("","Statemen missing']'");/*记录出错误信息*/
return;/*数组的定义不合法,退出常量定义处理函数*/
}
if(strcmp(getdq[0].name,":=")==0)
{
fprintf(out,"\n%d%d",0,36);/*output ':='*/
getsy();/*重新读入一个单词到输入栈*/
}
else{ 
yfchc("","Statemen missing':='");/*记录出错误信息*/
return;/*数组的定义不合法,退出常量定义处理函数*/
}
if(strcmp(getdq[0].name,"\"")==0)
{
fprintf(out,"\n%d%d",0,38);/*output '['*/
getsy();/*重新读入一个单词到输入栈*/
}
else{ 
yfchc("","Statemen missing'\"'");/*记录出错误信息*/
return;/*数组的定义不合法,退出常量定义处理函数*/
}
i=1;
while(getdq[0].t==5&&i<=clh1->a&&i<80&&doorkey<=3)
{
i=i+1;
strcat(clh->c,getdq[0].name);
getsy();
}
clh1=malloc(sizeof(struct cl));/*申请一个常量节点,并连接*/
style=2;
cln=set(llayer,&style,"");
strcpy(clh1->name,"");
clh1->type=2;
strcpy(clh->c,clh->c);
while(getdq[0].t==5&&i<80&&doorkey<=3)
{
i=i+1;
strcat(clh1->c,getdq[0].name);
getsy();
} 
clh1->line[0]=getdq[0].line;
clh1->line[1]=-1;
clh1->layer=llayer;
clh1->next=NULL;

if(clh->c[0]=='\0')
free(clh1);
else{
*cln=clh1;
fprintf(out,"\n%d %d",2,clh1);
}
if(strcmp(getdq[0].name,"\"")==0)
{
fprintf(out,"\n%d %d",0,38);
getsy();
}
else{
yfchc("","Statement missint'\"'");
return;
}
if(strcmp(getdq[0].name,",")==0)
{
fprintf(out,"\n%d %d",0,32);
getsy();
}
else if(strcmp(getdq[0].name,";")==0)
{
fprintf(out,"\n%d %d",0,33);
getsy();
return;
}
else{
yfchc("","Statement missing ','or ';'");
return;
}
}
else{
if(strcmp(getdq[1].name,":=")!=0)
{yfchc("","Statement missing':='");
return;
}
if (record==2 && strcmp(getdq[2].name,"\"")!=0)
{
yfchc("","Statement missing '\"'");
return;
}




clh=malloc(sizeof(struct cl));/*申请一个常量节点,并连接*/
style=2;
cln=set(llayer,&style,"");
*cln=clh;
strcpy(clh->name,getdq[0].name);
clh->type=record;
clh->line[0]=getdq[0].line;
clh->line[1]=-1;
clh->layer=llayer;
clh->next=NULL;/*填完部分常量表,但是内容没填*/
fprintf(out,"\n%d%d",2,clh);/*output 常量名*/
getsy();/*重新读入一个单词到输入栈*/
fprintf(out,"\n%d%d",0,36);/*output '['*/
getsy();/*重新读入一个单词到输入栈*/
clh1=malloc(sizeof(struct cl));/*申请一个常量节点,并连接*/
style=2;
cln=set(llayer,&style,"");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -