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

📄 bison.cc

📁 生成C++词法/语法分析的GNU语法分析器
💻 CC
📖 第 1 页 / 共 2 页
字号:
  register char *f = from;  register char *t = to;  register int i = count;  while (i-- > 0)    *t++ = *f++;}#endifint#ifdef YY_USE_CLASS YY_@_CLASS::#endif     YY_@_PARSE(YY_@_PARSE_PARAM)#ifndef __STDC__#ifndef __cplusplus#ifndef YY_USE_CLASS/* parameter definition without protypes */YY_@_PARSE_PARAM_DEF#endif#endif#endif{  register int yystate;  register int yyn;  register short *yyssp;  register YY_@_STYPE *yyvsp;  int yyerrstatus;      /*  number of tokens to shift before error messages enabled */  int yychar1=0;          /*  lookahead token as an internal (translated) token number */  short yyssa[YYINITDEPTH];     /*  the state stack                     */  YY_@_STYPE yyvsa[YYINITDEPTH];        /*  the semantic value stack            */  short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */  YY_@_STYPE *yyvs = yyvsa;     /*  to allow yyoverflow to reallocate them elsewhere */#ifdef YY_@_LSP_NEEDED  YY_@_LTYPE yylsa[YYINITDEPTH];        /*  the location stack                  */  YY_@_LTYPE *yyls = yylsa;  YY_@_LTYPE *yylsp;#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)#else#define YYPOPSTACK   (yyvsp--, yyssp--)#endif  int yystacksize = YYINITDEPTH;#ifdef YY_@_PURE  int YY_@_CHAR;  YY_@_STYPE YY_@_LVAL;  int YY_@_NERRS;#ifdef YY_@_LSP_NEEDED  YY_@_LTYPE YY_@_LLOC;#endif#endif  YY_@_STYPE yyval;             /*  the variable used to return         */				/*  semantic values from the action     */				/*  routines                            */  int yylen;/* start loop, in which YYGOTO may be used. */YYBEGINGOTO#if YY_@_DEBUG != 0  if (YY_@_DEBUG_FLAG)    fprintf(stderr, "Starting parse\n");#endif  yystate = 0;  yyerrstatus = 0;  YY_@_NERRS = 0;  YY_@_CHAR = YYEMPTY;          /* Cause a token to be read.  */  /* Initialize stack pointers.     Waste one element of value and location stack     so that they stay on the same level as the state stack.     The wasted elements are never initialized.  */  yyssp = yyss - 1;  yyvsp = yyvs;#ifdef YY_@_LSP_NEEDED  yylsp = yyls;#endif/* Push a new state, which is found in  yystate  .  *//* In all cases, when you get here, the value and location stacks   have just been pushed. so pushing a state here evens the stacks.  */YYLABEL(yynewstate)  *++yyssp = yystate;  if (yyssp >= yyss + yystacksize - 1)    {      /* Give user a chance to reallocate the stack */      /* Use copies of these so that the &'s don't force the real ones into memory. */      YY_@_STYPE *yyvs1 = yyvs;      short *yyss1 = yyss;#ifdef YY_@_LSP_NEEDED      YY_@_LTYPE *yyls1 = yyls;#endif      /* Get the current used size of the three stacks, in elements.  */      int size = yyssp - yyss + 1;#ifdef yyoverflow      /* Each stack pointer address is followed by the size of	 the data in use in that stack, in bytes.  */#ifdef YY_@_LSP_NEEDED      /* This used to be a conditional around just the two extra args,	 but that might be undefined if yyoverflow is a macro.  */      yyoverflow("parser stack overflow",		 &yyss1, size * sizeof (*yyssp),		 &yyvs1, size * sizeof (*yyvsp),		 &yyls1, size * sizeof (*yylsp),		 &yystacksize);#else      yyoverflow("parser stack overflow",		 &yyss1, size * sizeof (*yyssp),		 &yyvs1, size * sizeof (*yyvsp),		 &yystacksize);#endif      yyss = yyss1; yyvs = yyvs1;#ifdef YY_@_LSP_NEEDED      yyls = yyls1;#endif#else /* no yyoverflow */      /* Extend the stack our own way.  */      if (yystacksize >= YYMAXDEPTH)	{	  YY_@_ERROR("parser stack overflow");	  __ALLOCA_return(2);	}      yystacksize *= 2;      if (yystacksize > YYMAXDEPTH)	yystacksize = YYMAXDEPTH;      yyss = (short *) __ALLOCA_alloca (yystacksize * sizeof (*yyssp));      __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));      __ALLOCA_free(yyss1,yyssa);      yyvs = (YY_@_STYPE *) __ALLOCA_alloca (yystacksize * sizeof (*yyvsp));      __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));      __ALLOCA_free(yyvs1,yyvsa);#ifdef YY_@_LSP_NEEDED      yyls = (YY_@_LTYPE *) __ALLOCA_alloca (yystacksize * sizeof (*yylsp));      __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));      __ALLOCA_free(yyls1,yylsa);#endif#endif /* no yyoverflow */      yyssp = yyss + size - 1;      yyvsp = yyvs + size - 1;#ifdef YY_@_LSP_NEEDED      yylsp = yyls + size - 1;#endif#if YY_@_DEBUG != 0      if (YY_@_DEBUG_FLAG)	fprintf(stderr, "Stack size increased to %d\n", yystacksize);#endif      if (yyssp >= yyss + yystacksize - 1)	YYABORT;    }#if YY_@_DEBUG != 0  if (YY_@_DEBUG_FLAG)    fprintf(stderr, "Entering state %d\n", yystate);#endif  YYGOTO(yybackup);YYLABEL(yybackup)/* Do appropriate processing given the current state.  *//* Read a lookahead token if we need one and don't already have one.  *//* YYLABEL(yyresume) */  /* First try to decide what to do without reference to lookahead token.  */  yyn = yypact[yystate];  if (yyn == YYFLAG)    YYGOTO(yydefault);  /* Not known => get a lookahead token if don't already have one.  */  /* yychar is either YYEMPTY or YYEOF     or a valid token in external form.  */  if (YY_@_CHAR == YYEMPTY)    {#if YY_@_DEBUG != 0      if (YY_@_DEBUG_FLAG)	fprintf(stderr, "Reading a token: ");#endif      YY_@_CHAR = YYLEX;    }  /* Convert token to internal form (in yychar1) for indexing tables with */  if (YY_@_CHAR <= 0)           /* This means end of input. */    {      yychar1 = 0;      YY_@_CHAR = YYEOF;                /* Don't call YYLEX any more */#if YY_@_DEBUG != 0      if (YY_@_DEBUG_FLAG)	fprintf(stderr, "Now at end of input.\n");#endif    }  else    {      yychar1 = YYTRANSLATE(YY_@_CHAR);#if YY_@_DEBUG != 0      if (YY_@_DEBUG_FLAG)	{	  fprintf (stderr, "Next token is %d (%s", YY_@_CHAR, yytname[yychar1]);	  /* Give the individual parser a way to print the precise meaning	     of a token, for further debugging info.  */#ifdef YYPRINT	  YYPRINT (stderr, YY_@_CHAR, YY_@_LVAL);#endif	  fprintf (stderr, ")\n");	}#endif    }  yyn += yychar1;  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)    YYGOTO(yydefault);  yyn = yytable[yyn];  /* yyn is what to do for this token type in this state.     Negative => reduce, -yyn is rule number.     Positive => shift, yyn is new state.       New state is final state => don't bother to shift,       just return success.     0, or most negative number => error.  */  if (yyn < 0)    {      if (yyn == YYFLAG)	YYGOTO(yyerrlab);      yyn = -yyn;      YYGOTO(yyreduce);    }  else if (yyn == 0)    YYGOTO(yyerrlab);  if (yyn == YYFINAL)    YYACCEPT;  /* Shift the lookahead token.  */#if YY_@_DEBUG != 0  if (YY_@_DEBUG_FLAG)    fprintf(stderr, "Shifting token %d (%s), ", YY_@_CHAR, yytname[yychar1]);#endif  /* Discard the token being shifted unless it is eof.  */  if (YY_@_CHAR != YYEOF)    YY_@_CHAR = YYEMPTY;  *++yyvsp = YY_@_LVAL;#ifdef YY_@_LSP_NEEDED  *++yylsp = YY_@_LLOC;#endif  /* count tokens shifted since error; after three, turn off error status.  */  if (yyerrstatus) yyerrstatus--;  yystate = yyn;  YYGOTO(yynewstate);/* Do the default action for the current state.  */YYLABEL(yydefault)  yyn = yydefact[yystate];  if (yyn == 0)    YYGOTO(yyerrlab);/* Do a reduction.  yyn is the number of a rule to reduce with.  */YYLABEL(yyreduce)  yylen = yyr2[yyn];  if (yylen > 0)    yyval = yyvsp[1-yylen]; /* implement default value of the action */#if YY_@_DEBUG != 0  if (YY_@_DEBUG_FLAG)    {      int i;      fprintf (stderr, "Reducing via rule %d (line %d), ",	       yyn, yyrline[yyn]);      /* Print the symbols being reduced, and their result.  */      for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)	fprintf (stderr, "%s ", yytname[yyrhs[i]]);      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);    }#endif$   /* the action file gets copied in in place of this dollarsign  */  yyvsp -= yylen;  yyssp -= yylen;#ifdef YY_@_LSP_NEEDED  yylsp -= yylen;#endif#if YY_@_DEBUG != 0  if (YY_@_DEBUG_FLAG)    {      short *ssp1 = yyss - 1;      fprintf (stderr, "state stack now");      while (ssp1 != yyssp)	fprintf (stderr, " %d", *++ssp1);      fprintf (stderr, "\n");    }#endif  *++yyvsp = yyval;#ifdef YY_@_LSP_NEEDED  yylsp++;  if (yylen == 0)    {      yylsp->first_line = YY_@_LLOC.first_line;      yylsp->first_column = YY_@_LLOC.first_column;      yylsp->last_line = (yylsp-1)->last_line;      yylsp->last_column = (yylsp-1)->last_column;      yylsp->text = 0;    }  else    {      yylsp->last_line = (yylsp+yylen-1)->last_line;      yylsp->last_column = (yylsp+yylen-1)->last_column;    }#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];  YYGOTO(yynewstate);YYLABEL(yyerrlab)   /* here on detecting error */  if (! yyerrstatus)    /* If not already recovering from an error, report this error.  */    {      ++YY_@_NERRS;#ifdef YY_@_ERROR_VERBOSE      yyn = yypact[yystate];      if (yyn > YYFLAG && yyn < YYLAST)	{	  int size = 0;	  char *msg;	  int x, count;	  count = 0;	  /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */	  for (x = (yyn < 0 ? -yyn : 0);	       x < (sizeof(yytname) / sizeof(char *)); x++)	    if (yycheck[x + yyn] == x)	      size += strlen(yytname[x]) + 15, count++;	  msg = (char *) malloc(size + 15);	  if (msg != 0)	    {	      strcpy(msg, "parse error");	      if (count < 5)		{		  count = 0;		  for (x = (yyn < 0 ? -yyn : 0);		       x < (sizeof(yytname) / sizeof(char *)); x++)		    if (yycheck[x + yyn] == x)		      {			strcat(msg, count == 0 ? ", expecting `" : " or `");			strcat(msg, yytname[x]);			strcat(msg, "'");			count++;		      }		}	      YY_@_ERROR(msg);	      free(msg);	    }	  else	    YY_@_ERROR ("parse error; also virtual memory exceeded");	}      else#endif /* YY_@_ERROR_VERBOSE */	YY_@_ERROR("parse error");    }  YYGOTO(yyerrlab1);YYLABEL(yyerrlab1)   /* here on error raised explicitly by an action */  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 (YY_@_CHAR == YYEOF)	YYABORT;#if YY_@_DEBUG != 0      if (YY_@_DEBUG_FLAG)	fprintf(stderr, "Discarding token %d (%s).\n", YY_@_CHAR, yytname[yychar1]);#endif      YY_@_CHAR = YYEMPTY;    }  /* Else will try to reuse lookahead token     after shifting the error token.  */  yyerrstatus = 3;              /* Each real token shifted decrements this */  YYGOTO(yyerrhandle);YYLABEL(yyerrdefault)  /* current state does not do anything special for the error token. */#if 0  /* This is wrong; only states that explicitly want error tokens     should shift them.  */  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/  if (yyn) YYGOTO(yydefault);#endifYYLABEL(yyerrpop)   /* pop the current state because it cannot handle the error token */  if (yyssp == yyss) YYABORT;  yyvsp--;  yystate = *--yyssp;#ifdef YY_@_LSP_NEEDED  yylsp--;#endif#if YY_@_DEBUG != 0  if (YY_@_DEBUG_FLAG)    {      short *ssp1 = yyss - 1;      fprintf (stderr, "Error: state stack now");      while (ssp1 != yyssp)	fprintf (stderr, " %d", *++ssp1);      fprintf (stderr, "\n");    }#endifYYLABEL(yyerrhandle)  yyn = yypact[yystate];  if (yyn == YYFLAG)    YYGOTO(yyerrdefault);  yyn += YYTERROR;  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)    YYGOTO(yyerrdefault);  yyn = yytable[yyn];  if (yyn < 0)    {      if (yyn == YYFLAG)	YYGOTO(yyerrpop);      yyn = -yyn;      YYGOTO(yyreduce);    }  else if (yyn == 0)    YYGOTO(yyerrpop);  if (yyn == YYFINAL)    YYACCEPT;#if YY_@_DEBUG != 0  if (YY_@_DEBUG_FLAG)    fprintf(stderr, "Shifting error token, ");#endif  *++yyvsp = YY_@_LVAL;#ifdef YY_@_LSP_NEEDED  *++yylsp = YY_@_LLOC;#endif  yystate = yyn;  YYGOTO(yynewstate);/* end loop, in which YYGOTO may be used. */  YYENDGOTO}/* END */$ /* section 3 *//* AFTER END , NEVER READ !!! */

⌨️ 快捷键说明

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