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

📄 test.tab.c

📁 对pl0语言程序的语法分析源程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    break;}
case 44:
#line 107 "test.y"
{printf("表达式->+ 项\n");;
    break;}
case 45:
#line 108 "test.y"
{printf("表达式->- 项\n");;
    break;}
case 46:
#line 112 "test.y"
{printf("加法和项的串->加法和项的串 加法运算符 项\n");;
    break;}
case 47:
#line 113 "test.y"
{printf("加法和项的串->加法运算符 项\n");;
    break;}
case 48:
#line 117 "test.y"
{printf("项->因子 乘法运算符和因子的串\n");;
    break;}
case 49:
#line 118 "test.y"
{printf("项->因子\n");;
    break;}
case 50:
#line 122 "test.y"
{printf("乘法运算符和因子的串->乘法运算符和因子的串 乘法运算符 因子\n");;
    break;}
case 51:
#line 123 "test.y"
{printf("乘法运算符和因子的串->乘法运算符 因子\n");;
    break;}
case 52:
#line 127 "test.y"
{printf("因子->ID\n");;
    break;}
case 53:
#line 128 "test.y"
{printf("因子->NUM\n");;
    break;}
case 54:
#line 129 "test.y"
{printf("因子->( 表达式 )\n");;
    break;}
case 55:
#line 133 "test.y"
{printf("加法运算符->+\n");;
    break;}
case 56:
#line 134 "test.y"
{printf("加法运算符->-\n");;
    break;}
case 57:
#line 138 "test.y"
{printf("乘法运算符->*\n");;
    break;}
case 58:
#line 139 "test.y"
{printf("乘法运算符->/\n");;
    break;}
case 59:
#line 143 "test.y"
{printf("关系运算符->=\n");;
    break;}
case 60:
#line 144 "test.y"
{printf("关系运算符->#\n");;
    break;}
case 61:
#line 145 "test.y"
{printf("关系运算符-><\n");;
    break;}
case 62:
#line 146 "test.y"
{printf("关系运算符->>\n");;
    break;}
case 63:
#line 147 "test.y"
{printf("关系运算符-><=\n");;
    break;}
case 64:
#line 148 "test.y"
{printf("关系运算符->>=\n");;
    break;}
case 65:
#line 152 "test.y"
{printf("当型循环语句->WHILE 条件 DO 语句\n");;
    break;}
case 66:
#line 156 "test.y"
{printf("过程条用语句->CALL ID\n");;
    break;}
case 67:
#line 160 "test.y"
{printf("读语句->READ ( ID 标识符串 )\n");;
    break;}
case 68:
#line 161 "test.y"
{printf("读语句->READ ( ID )\n");;
    break;}
case 69:
#line 165 "test.y"
{printf("写语句->WRITE ( 表达式 表达式串 )\n");;
    break;}
case 70:
#line 166 "test.y"
{printf("写语句->WRITE ( 表达式 )\n");;
    break;}
case 71:
#line 170 "test.y"
{printf("表达式串->表达式串 , 表达式\n");;
    break;}
case 72:
#line 171 "test.y"
{printf("表达式串->, 表达式\n");;
    break;}
}

#line 705 "bison.simple"


  yyvsp -= yylen;
  yyssp -= yylen;
#if YYLSP_NEEDED
  yylsp -= yylen;
#endif

#if YYDEBUG
  if (yydebug)
    {
      short *yyssp1 = yyss - 1;
      YYFPRINTF (stderr, "state stack now");
      while (yyssp1 != yyssp)
	YYFPRINTF (stderr, " %d", *++yyssp1);
      YYFPRINTF (stderr, "\n");
    }
#endif

  *++yyvsp = yyval;
#if YYLSP_NEEDED
  *++yylsp = yyloc;
#endif

  /* 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 - YYNTBASE] + *yyssp;
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTBASE];

  goto yynewstate;


/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;

#ifdef YYERROR_VERBOSE
      yyn = yypact[yystate];

      if (yyn > YYFLAG && yyn < YYLAST)
	{
	  YYSIZE_T yysize = 0;
	  char *yymsg;
	  int yyx, yycount;

	  yycount = 0;
	  /* Start YYX at -YYN if negative to avoid negative indexes in
	     YYCHECK.  */
	  for (yyx = yyn < 0 ? -yyn : 0;
	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
	    if (yycheck[yyx + yyn] == yyx)
	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;
	  yysize += yystrlen ("parse error, unexpected ") + 1;
	  yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
	  yymsg = (char *) YYSTACK_ALLOC (yysize);
	  if (yymsg != 0)
	    {
	      char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
	      yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);

	      if (yycount < 5)
		{
		  yycount = 0;
		  for (yyx = yyn < 0 ? -yyn : 0;
		       yyx < (int) (sizeof (yytname) / sizeof (char *));
		       yyx++)
		    if (yycheck[yyx + yyn] == yyx)
		      {
			const char *yyq = ! yycount ? ", expecting " : " or ";
			yyp = yystpcpy (yyp, yyq);
			yyp = yystpcpy (yyp, yytname[yyx]);
			yycount++;
		      }
		}
	      yyerror (yymsg);
	      YYSTACK_FREE (yymsg);
	    }
	  else
	    yyerror ("parse error; also virtual memory exhausted");
	}
      else
#endif /* defined (YYERROR_VERBOSE) */
	yyerror ("parse error");
    }
  goto yyerrlab1;


/*--------------------------------------------------.
| yyerrlab1 -- error raised explicitly by an action |
`--------------------------------------------------*/
yyerrlab1:
  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)
	YYABORT;
      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
		  yychar, yytname[yychar1]));
      yychar = YYEMPTY;
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */

  yyerrstatus = 3;		/* Each real token shifted decrements this */

  goto yyerrhandle;


/*-------------------------------------------------------------------.
| yyerrdefault -- current state does not do anything special for the |
| error token.                                                       |
`-------------------------------------------------------------------*/
yyerrdefault:
#if 0
  /* This is wrong; only states that explicitly want error tokens
     should shift them.  */

  /* If its default is to accept any token, ok.  Otherwise pop it.  */
  yyn = yydefact[yystate];
  if (yyn)
    goto yydefault;
#endif


/*---------------------------------------------------------------.
| yyerrpop -- pop the current state because it cannot handle the |
| error token                                                    |
`---------------------------------------------------------------*/
yyerrpop:
  if (yyssp == yyss)
    YYABORT;
  yyvsp--;
  yystate = *--yyssp;
#if YYLSP_NEEDED
  yylsp--;
#endif

#if YYDEBUG
  if (yydebug)
    {
      short *yyssp1 = yyss - 1;
      YYFPRINTF (stderr, "Error: state stack now");
      while (yyssp1 != yyssp)
	YYFPRINTF (stderr, " %d", *++yyssp1);
      YYFPRINTF (stderr, "\n");
    }
#endif

/*--------------.
| yyerrhandle.  |
`--------------*/
yyerrhandle:
  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yyerrdefault;

  yyn += YYTERROR;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
    goto yyerrdefault;

  yyn = yytable[yyn];
  if (yyn < 0)
    {
      if (yyn == YYFLAG)
	goto yyerrpop;
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrpop;

  if (yyn == YYFINAL)
    YYACCEPT;

  YYDPRINTF ((stderr, "Shifting error token, "));

  *++yyvsp = yylval;
#if YYLSP_NEEDED
  *++yylsp = yylloc;
#endif

  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturn;

/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturn;

/*---------------------------------------------.
| yyoverflowab -- parser overflow comes here.  |
`---------------------------------------------*/
yyoverflowlab:
  yyerror ("parser stack overflow");
  yyresult = 2;
  /* Fall through.  */

yyreturn:
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif
  return yyresult;
}
#line 174 "test.y"


int main()
{
    FILE * fp;
    char FILENAME[30];
    printf("********************************************************************************");
    printf("\t\t    A lex & yacc analyzer for PL0\nBy ZhaoYang No.50\n2004.11.15\n");
    printf("********************************************************************************\n\n");
    printf("Please enter the file name:\n");
    scanf("%s",FILENAME);
    if((fp=fopen(FILENAME,"r"))==NULL)
    { 
    	printf("Can not open the file!\n");
        return 1;
    }
    printf("\n----------------------------所有的终结符----------------------------------------\n");
    printf("IF THEN WHILE DO READ WRITE CALL BEG END CONST VAR PROCEDURE ODD + - * / ; ( ) , = := # <= >= < > ID NUM\n\n");
    printf("Start:\n");
	yyin=fp;
    yyparse();
    fclose(fp);
    printf("\n------------------------------规约成功------------------------------------------\n");
    return 0;
}

int yyerror(char * msg)
{
	printf("Error:%s at line number:%d\n",msg, yylineno);
        return 0;
}

    
    

⌨️ 快捷键说明

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