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

📄 y.tab.c

📁 本源码为一个编译原理课程设计程序,它采用了YACC和LEX实现了一个功能强大的计算器编译器!
💻 C
📖 第 1 页 / 共 3 页
字号:
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)    goto yydefault;  yyn = yytable[yyn];  if (yyn <= 0)    {      if (yyn == 0 || yyn == YYTABLE_NINF)	goto yyerrlab;      yyn = -yyn;      goto yyreduce;    }  if (yyn == YYFINAL)    YYACCEPT;  /* Shift the lookahead token.  */  YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));  /* Discard the token being shifted unless it is eof.  */  if (yychar != YYEOF)    yychar = YYEMPTY;  *++yyvsp = yylval;  /* Count tokens shifted since error; after three, turn off error     status.  */  if (yyerrstatus)    yyerrstatus--;  yystate = yyn;  goto yynewstate;/*-----------------------------------------------------------.| yydefault -- do the default action for the current state.  |`-----------------------------------------------------------*/yydefault:  yyn = yydefact[yystate];  if (yyn == 0)    goto yyerrlab;  goto yyreduce;/*-----------------------------.| yyreduce -- Do a reduction.  |`-----------------------------*/yyreduce:  /* yyn is the number of a rule to reduce with.  */  yylen = yyr2[yyn];  /* If YYLEN is nonzero, implement the default value of the action:     `$$ = $1'.     Otherwise, the following line sets YYVAL to garbage.     This behavior is undocumented and Bison     users should not rely upon it.  Assigning to YYVAL     unconditionally makes the parser a bit smaller, and it avoids a     GCC warning that YYVAL may be used uninitialized.  */  yyval = yyvsp[1-yylen];  YY_REDUCE_PRINT (yyn);  switch (yyn)    {        case 3:#line 39 "calc.y"    {printf("--> ");}    break;  case 4:#line 40 "calc.y"    {yyerrok;printf("\n--> ");}    break;  case 7:#line 45 "calc.y"    {		if(dflag==DEC_ON)printf( "\t=%g\n--> " , yyvsp[0] );		else if(dflag==HEX_ON)printf( "\t=0x%08X\n--> " , (BIGINT)yyvsp[0] );		else printf( "\t=0%o\n--> " , (BIGINT)yyvsp[0] );		}    break;  case 8:#line 50 "calc.y"    {			       i=(int)yyvsp[-2]; reg[i] = yyvsp[0] ; 			       if(dflag==DEC_ON) printf( "\t%c=%g\n--> " , 'a'+i,reg[i] );			       else if(dflag==HEX_ON) printf( "\t%c=0x%08X\n--> " , 'a'+i,(BIGINT)reg[i] );			       else  printf( "\t%c=0%o\n--> " , 'a'+i,(BIGINT)reg[i] );			      }    break;  case 9:#line 58 "calc.y"    { yyval = yyvsp[-2] + yyvsp[0] ; }    break;  case 10:#line 59 "calc.y"    { yyval = yyvsp[-2] - yyvsp[0] ; }    break;  case 11:#line 60 "calc.y"    { yyval = yyvsp[-2] * yyvsp[0] ; }    break;  case 12:#line 61 "calc.y"    { yyval = yyvsp[-2] / yyvsp[0] ; }    break;  case 13:#line 62 "calc.y"    { yyval = (BIGINT)yyvsp[-2] % (BIGINT)yyvsp[0] ; }    break;  case 14:#line 63 "calc.y"    { yyval = (BIGINT)yyvsp[-2] & (BIGINT)yyvsp[0] ; }    break;  case 15:#line 64 "calc.y"    { yyval = (BIGINT)yyvsp[-2] | (BIGINT)yyvsp[0] ; }    break;  case 16:#line 65 "calc.y"    { yyval = (BIGINT)yyvsp[-2] ^ (BIGINT)yyvsp[0] ; }    break;  case 17:#line 66 "calc.y"    { yyval = (BIGINT)yyvsp[-2] << (BIGINT)yyvsp[0] ; }    break;  case 18:#line 67 "calc.y"    { yyval = (BIGINT)yyvsp[-2] >> (BIGINT)yyvsp[0] ; }    break;  case 19:#line 68 "calc.y"    { yyval = (BIGINT)yyvsp[-2] && (BIGINT)yyvsp[0] ; }    break;  case 20:#line 69 "calc.y"    { yyval = (BIGINT)yyvsp[-2] || (BIGINT)yyvsp[0] ; }    break;  case 21:#line 70 "calc.y"    { yyval = yyvsp[-2]<yyvsp[0]?1:0; }    break;  case 22:#line 71 "calc.y"    { yyval = yyvsp[-2]>yyvsp[0]?1:0; }    break;  case 23:#line 72 "calc.y"    { yyval = yyvsp[-1] ; }    break;  case 24:#line 73 "calc.y"    { yyval = -yyvsp[0] ; }    break;  case 25:#line 74 "calc.y"    { yyval = ~((BIGINT)yyvsp[0]); }    break;  case 26:#line 75 "calc.y"    { yyval = !( (BIGINT)yyvsp[0] ) ; }    break;  case 27:#line 76 "calc.y"    { yyval = yyvsp[0] ; }    break;  case 28:#line 77 "calc.y"    { ival=(int)yyvsp[0];yyval = reg[ival] ; }    break;  case 29:#line 78 "calc.y"    { yyval =sin(yyvsp[0]) ; }    break;  case 30:#line 79 "calc.y"    { yyval =cos(yyvsp[0]) ; }    break;  case 31:#line 80 "calc.y"    { yyval =tan(yyvsp[0]) ; }    break;  case 32:#line 81 "calc.y"    { yyval =log(yyvsp[0]) ; }    break;  case 33:#line 82 "calc.y"    { yyval =abs(yyvsp[0]) ; }    break;  case 34:#line 83 "calc.y"    { yyval =sqrt(yyvsp[0]) ; }    break;  case 35:#line 86 "calc.y"    { exit(0); }    break;  case 36:#line 87 "calc.y"    { printf("\033[2J\033[1;1H\n--> "); }    break;  case 37:#line 88 "calc.y"    { dflag=HEX_ON; printf(">> Hex display mod on!\n--> "); }    break;  case 38:#line 89 "calc.y"    { dflag=DEC_ON; printf(">> Dec display mod on!\n--> "); }    break;  case 39:#line 90 "calc.y"    { dflag=OCT_ON; printf(">> Oct display mod on!\n--> "); }    break;  case 40:#line 91 "calc.y"    { 			for(i=0;i<26;i++)			{			    if(dflag==DEC_ON)printf("\t%c=%g\n",'a'+i,reg[i]); 			    else if(dflag==HEX_ON)printf("\t%c=0x%08X\n",'a'+i,(BIGINT)reg[i]);			    else printf("\t%c=0%o\n",'a'+i,(BIGINT)reg[i]);			 }		 printf("--> ");		 }    break;  case 41:#line 100 "calc.y"    { for(i=0;i<26;i++)reg[i]=0; printf(">>All registers erased!\n--> ");}    break;  case 42:#line 101 "calc.y"    {			 printf(">> COMMANDS:\n");			 printf("> help: Display this help section.\n");			 printf("> clear: Clear the screen.\n");			 printf("> dec: Decimal mode to display  numbers or registers.\n");			 printf("> hex: Hexadecimal mode to display numbers or registers.\n");			 printf("> oct: Octal mode to display numbers or registers.\n");			 printf("> list: List the values in the 26 registers which are ranged from 'a'/'A' to 'z'/'Z'.\n");			 printf("> erase: Reset all registers to 0.\n");			 printf("> exit: Quit this program.\n");			 printf("--> ");			 }    break;    }/* Line 999 of yacc.c.  */#line 1349 "y.tab.c"  yyvsp -= yylen;  yyssp -= yylen;  YY_STACK_PRINT (yyss, yyssp);  *++yyvsp = yyval;  /* Now `shift' the result of the reduction.  Determine what state     that goes to, based on the state we popped back to and the rule     number reduced by.  */  yyn = yyr1[yyn];  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)    yystate = yytable[yystate];  else    yystate = yydefgoto[yyn - YYNTOKENS];  goto yynewstate;/*------------------------------------.| yyerrlab -- here on detecting error |`------------------------------------*/yyerrlab:  /* If not already recovering from an error, report this error.  */  if (!yyerrstatus)    {      ++yynerrs;#if YYERROR_VERBOSE      yyn = yypact[yystate];      if (YYPACT_NINF < yyn && yyn < YYLAST)	{	  YYSIZE_T yysize = 0;	  int yytype = YYTRANSLATE (yychar);	  const char* yyprefix;	  char *yymsg;	  int yyx;	  /* Start YYX at -YYN if negative to avoid negative indexes in	     YYCHECK.  */	  int yyxbegin = yyn < 0 ? -yyn : 0;	  /* Stay within bounds of both yycheck and yytname.  */	  int yychecklim = YYLAST - yyn;	  int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;	  int yycount = 0;	  yyprefix = ", expecting ";	  for (yyx = yyxbegin; yyx < yyxend; ++yyx)	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)	      {		yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);		yycount += 1;		if (yycount == 5)		  {		    yysize = 0;		    break;		  }	      }	  yysize += (sizeof ("syntax error, unexpected ")		     + yystrlen (yytname[yytype]));	  yymsg = (char *) YYSTACK_ALLOC (yysize);	  if (yymsg != 0)	    {	      char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");	      yyp = yystpcpy (yyp, yytname[yytype]);	      if (yycount < 5)		{		  yyprefix = ", expecting ";		  for (yyx = yyxbegin; yyx < yyxend; ++yyx)		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)		      {			yyp = yystpcpy (yyp, yyprefix);			yyp = yystpcpy (yyp, yytname[yyx]);			yyprefix = " or ";		      }		}	      yyerror (yymsg);	      YYSTACK_FREE (yymsg);	    }	  else	    yyerror ("syntax error; also virtual memory exhausted");	}      else#endif /* YYERROR_VERBOSE */	yyerror ("syntax error");    }  if (yyerrstatus == 3)    {      /* If just tried and failed to reuse lookahead token after an	 error, discard it.  */      /* Return failure if at end of input.  */      if (yychar == YYEOF)        {	  /* Pop the error token.  */          YYPOPSTACK;	  /* Pop the rest of the stack.  */	  while (yyss < yyssp)	    {	      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);	      yydestruct (yystos[*yyssp], yyvsp);	      YYPOPSTACK;	    }	  YYABORT;        }      YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);      yydestruct (yytoken, &yylval);      yychar = YYEMPTY;    }  /* Else will try to reuse lookahead token after shifting the error     token.  */  goto yyerrlab1;/*----------------------------------------------------.| yyerrlab1 -- error raised explicitly by an action.  |`----------------------------------------------------*/yyerrlab1:  yyerrstatus = 3;	/* Each real token shifted decrements this.  */  for (;;)    {      yyn = yypact[yystate];      if (yyn != YYPACT_NINF)	{	  yyn += YYTERROR;	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)	    {	      yyn = yytable[yyn];	      if (0 < yyn)		break;	    }	}      /* Pop the current state because it cannot handle the error token.  */      if (yyssp == yyss)	YYABORT;      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);      yydestruct (yystos[yystate], yyvsp);      yyvsp--;      yystate = *--yyssp;      YY_STACK_PRINT (yyss, yyssp);    }  if (yyn == YYFINAL)    YYACCEPT;  YYDPRINTF ((stderr, "Shifting error token, "));  *++yyvsp = yylval;  yystate = yyn;  goto yynewstate;/*-------------------------------------.| yyacceptlab -- YYACCEPT comes here.  |`-------------------------------------*/yyacceptlab:  yyresult = 0;  goto yyreturn;/*-----------------------------------.| yyabortlab -- YYABORT comes here.  |`-----------------------------------*/yyabortlab:  yyresult = 1;  goto yyreturn;#ifndef yyoverflow/*----------------------------------------------.| yyoverflowlab -- parser overflow comes here.  |`----------------------------------------------*/yyoverflowlab:  yyerror ("parser stack overflow");  yyresult = 2;  /* Fall through.  */#endifyyreturn:#ifndef yyoverflow  if (yyss != yyssa)    YYSTACK_FREE (yyss);#endif  return yyresult;}#line 115 "calc.y"int yyerror(char *str){         fprintf(stderr,"Error: %s\n",str);         return 1;      }int yywrap(){                       return 1;}int main(){	   yyparse();}

⌨️ 快捷键说明

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