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

📄 btyaccpa.ske

📁 yacc源码
💻 SKE
📖 第 1 页 / 共 2 页
字号:
        // If this is a first conflict in the stack, start saving lexemes        if (!yylexemes) {#ifndef __cplusplus          yylexemes = (Yshort *)malloc(YYSTACKGROWTH*sizeof(Yshort));          yylvals = (YYSTYPE *)malloc(YYSTACKGROWTH*sizeof(YYSTYPE));#else  /* C++ */          yylexemes = new Yshort[YYSTACKGROWTH];          yylvals = new YYSTYPE[YYSTACKGROWTH];#endif /* C++ */          yylvlim = yylvals + YYSTACKGROWTH;         }        if (yylvp == yylve) {          yylvp = yylve = yylvals;          yylexp = yylexemes;          if (yychar >= 0) {            *yylve++ = yylval;            *yylexp = yychar;            yychar = -1;           }         }       }      if (yychar >= 0) {        yylvp--, yylexp--;        yychar = -1;       }      save->lexeme = yylvp - yylvals;      yyps->save = save;     }    if (yytable[yyn] == ctry) {#if YYDEBUG      if (yydebug)        printf("yydebug: state %d, shifting to state %d\n",               yystate, yyctable[ctry]);#endif      if (yychar < 0)        yylvp++, yylexp++;      yychar = -1;      if (yyps->errflag > 0) --yyps->errflag;      yystate = yyctable[ctry];      goto yyshift;     } else {      yyn = yyctable[ctry];      goto yyreduce;     }   }  //  // Is action a shift?  //  if ((yyn = yysindex[yystate]) &&      (yyn += yychar) >= 0 &&      yyn <= YYTABLESIZE &&      yycheck[yyn] == yychar) {#if YYDEBUG    if (yydebug)      printf("yydebug: state %d, shifting to state %d\n",             yystate, yytable[yyn]);#endif    yychar = (-1);    if (yyps->errflag > 0)  --yyps->errflag;    yystate = yytable[yyn];  yyshift:    if (yyps->ssp >= yyps->ss + yyps->stacksize - 1) {      YYMORESTACK;    }    *++(yyps->ssp) = yystate;    *++(yyps->vsp) = yylval;    goto yyloop;  }  if ((yyn = yyrindex[yystate]) &&      (yyn += yychar) >= 0 &&      yyn <= YYTABLESIZE &&      yycheck[yyn] == yychar) {    yyn = yytable[yyn];    goto yyreduce;  }  //  // Action: error  //  if (yyps->errflag) goto yyinrecovery;  yynewerrflag = 1;  goto yyerrhandler;yyerrlab:  yynewerrflag = 0;yyerrhandler:  while (yyps->save) {     int ctry;     struct yyparsestate *save = yyps->save;#if YYDEBUG    if (yydebug)      printf("yydebug: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",             yystate, yyps->save->state, yylvp - yylvals - yyps->save->lexeme);#endif    // Memorize most forward-looking error state in case    // it's really an error.    if(yyerrctx==NULL || yyerrctx->lexeme<yylvp-yylvals) {      // Free old saved error context state      if(yyerrctx) YYFREESTATE(yyerrctx);      // Create and fill out new saved error context state      yyerrctx = YYNEWSTATE(yyps->ssp - yyps->ss);      yyerrctx->save = yyps->save;      yyerrctx->state = yystate;      yyerrctx->errflag = yyps->errflag;      yyerrctx->ssp = yyerrctx->ss + (yyps->ssp - yyps->ss);      yyerrctx->vsp = yyerrctx->vs + (yyps->vsp - yyps->vs);      memcpy (yyerrctx->ss, yyps->ss, (yyps->ssp - yyps->ss + 1)*sizeof(Yshort));      YYSCOPY(yyerrctx->vs, yyps->vs, (yyps->ssp - yyps->ss + 1));      yyerrctx->lexeme = yylvp - yylvals;    }    yylvp  = yylvals   + save->lexeme;    yylexp = yylexemes + save->lexeme;    yychar = -1;    yyps->ssp = yyps->ss + (save->ssp - save->ss);    yyps->vsp = yyps->vs + (save->vsp - save->vs);    memcpy (yyps->ss, save->ss, (yyps->ssp - yyps->ss + 1) * sizeof(Yshort));    YYSCOPY(yyps->vs, save->vs,  yyps->vsp - yyps->vs + 1);    ctry = ++save->ctry;    yystate = save->state;    // We tried shift, try reduce now    if ((yyn = yyctable[ctry]) >= 0) {      goto yyreduce;    }    yyps->save = save->save;    YYFREESTATE(save);    //    // Nothing left on the stack -- error    //    if (!yyps->save) {#if YYDEBUG      if (yydebug) {        printf("yydebug: trial parse FAILED, entering ERROR mode\n");      }#endif      // Restore state as it was in the most forward-advanced error      yylvp  = yylvals   + yyerrctx->lexeme;      yylexp = yylexemes + yyerrctx->lexeme;      yychar = yylexp[-1];      yylval = yylvp[-1];      yyps->ssp = yyps->ss + (yyerrctx->ssp - yyerrctx->ss);      yyps->vsp = yyps->vs + (yyerrctx->vsp - yyerrctx->vs);      memcpy (yyps->ss, yyerrctx->ss, (yyps->ssp - yyps->ss + 1) * sizeof(Yshort));      YYSCOPY(yyps->vs, yyerrctx->vs,  yyps->vsp - yyps->vs + 1);      yystate = yyerrctx->state;      YYFREESTATE(yyerrctx);      yyerrctx = NULL;    }    yynewerrflag = 1;   }  if (yynewerrflag) {#ifdef YYERROR_DETAILED    yyerror_detailed("syntax error", yychar, yylval);#else    yyerror("syntax error");#endif  }  ++yynerrs; yyinrecovery:  if (yyps->errflag < 3) {    yyps->errflag = 3;    for (;;) {      if ((yyn = yysindex[*(yyps->ssp)]) && (yyn += YYERRCODE) >= 0 &&          yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) {#if YYDEBUG        if (yydebug)          printf("yydebug: state %d, ERROR recovery %s state %d\n",                 *(yyps->ssp), "shifting to", yytable[yyn]);#endif        /* Use label yyerrlab, so that compiler does not warn */        if(yyps->errflag != yyps->errflag) goto yyerrlab;        yystate = yytable[yyn];        goto yyshift;       } else {#if YYDEBUG        if (yydebug)          printf("yydebug: ERROR recovery discarding state %d\n",                 *(yyps->ssp));#endif        if ((yyps->ssp) <= (yyps->ss)) goto yyabort;        --(yyps->ssp);        --(yyps->vsp);      }    }  } else {    if (yychar == 0) goto yyabort;#if YYDEBUG    if (yydebug) {      yys = 0;      if (yychar <= YYMAXTOKEN) yys = yyname[yychar];      if (!yys) yys = "illegal-symbol";      printf("yydebug: state %d, ERROR recovery discards token %d (%s)\n",             yystate, yychar, yys);     }#endif    yychar = (-1);    goto yyloop;  }  //  // Reduce  //yyreduce:  yym = yylen[yyn];#if YYDEBUG  if (yydebug) {    printf("yydebug: state %d, reducing by rule %d (%s)",           yystate, yyn, yyrule[yyn]);#ifdef YYDBPR    if (yym) {      int i;      printf("<");      for (i=yym; i>0; i--) {        if (i!=yym) printf(", ");        YYDBPR((yyps->vsp)[1-i]);      }      printf(">");    }#endif    printf("\n");  }#endif  if (yyps->ssp + 1 - yym >= yyps->ss + yyps->stacksize) {    YYMORESTACK;  }  /* $$ = $1 default action */  if(yym > 0) {    yyps->val = (yyps->vsp)[1-yym];  }  switch (yyn) {%% trailer  }#if YYDEBUG && defined(YYDBPR)  if (yydebug) {    printf("yydebug: after reduction, result is ");    YYDBPR(yyps->val);    printf("\n");  }#endif  yyps->ssp -= yym;  yystate = *(yyps->ssp);  yyps->vsp -= yym;  yym = yylhs[yyn];  if (yystate == 0 && yym == 0) {#if YYDEBUG    if (yydebug)      printf("yydebug: after reduction, %s from state 0 to state %d\n",             "shifting", YYFINAL);#endif    yystate = YYFINAL;    *++(yyps->ssp) = YYFINAL;    *++(yyps->vsp) = (yyps->val);    if (yychar < 0) {      if ((yychar = YYLEX) < 0)        yychar = 0;#if YYDEBUG      if (yydebug) {        yys = 0;        if (yychar <= YYMAXTOKEN) yys = yyname[yychar];        if (!yys) yys = "illegal-symbol";        printf("yydebug: state %d, reading %d (%s)\n",               YYFINAL, yychar, yys);       }#endif    }    if (yychar == 0) goto yyaccept;    goto yyloop;  }  if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&      yyn <= YYTABLESIZE && yycheck[yyn] == yystate)    yystate = yytable[yyn];  else    yystate = yydgoto[yym];#if YYDEBUG  if (yydebug)    printf("yydebug: after reduction, %s from state %d to state %d\n",           "shifting", *(yyps->ssp), yystate);#endif  if (yyps->ssp >= yyps->ss + yyps->stacksize - 1) {    YYMORESTACK;  }  *++(yyps->ssp) = yystate;  *++(yyps->vsp) = yyps->val;  goto yyloop;  //  // Reduction declares that this path is valid.  // Set yypath and do a full parse  //yyvalid:  if (yypath) {    goto yyabort;  }  while (yyps->save) {    struct yyparsestate *save = yyps->save;    yyps->save = save->save;    save->save = yypath;    yypath = save;  }#if YYDEBUG  if (yydebug)    printf("yydebug: CONFLICT trial successful, backtracking to state %d, %d tokens\n",           yypath->state, yylvp - yylvals - yypath->lexeme);#endif  if(yyerrctx) {    YYFREESTATE(yyerrctx);    yyerrctx = NULL;  }  yychar = -1;  yyps->ssp = yyps->ss + (yypath->ssp - yypath->ss);  yyps->vsp = yyps->vs + (yypath->vsp - yypath->vs);  memcpy (yyps->ss, yypath->ss, (yyps->ssp - yyps->ss + 1) * sizeof(Yshort));  YYSCOPY(yyps->vs, yypath->vs,  yyps->vsp - yyps->vs + 1);  yylvp = yylvals + yypath->lexeme;  yylexp = yylexemes + yypath->lexeme;  yystate = yypath->state;  goto yyloop;yyabort:  while (yyps) {    struct yyparsestate *save = yyps;    yyps = save->save;    YYFREESTATE(save);  }  while (yypath) {    struct yyparsestate *save = yypath;    yypath = save->save;    YYFREESTATE(save);   }  return (1);yyaccept:  if (yyps->save) goto yyvalid;  while (yyps) {    struct yyparsestate *save = yyps;    yyps = save->save;    YYFREESTATE(save);  }  while (yypath) {    struct yyparsestate *save = yypath;    yypath = save->save;    YYFREESTATE(save);   }  return (0);}

⌨️ 快捷键说明

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