📄 snapparse.c
字号:
{ value_t *_v; if ((value_exc > MAX_VINT) || (value_exc < 0)) { fprintf(stderr, "%s:%d: int literal %d out of bounds (%d,%d)\n", __FILE__,__LINE__,value_exc,0,MAX_VINT); fflush(stderr); exit(1); } memalloc(_v,value_t *,sizeof(value_t)); SET_TAG(*_v,EXCV); SET_INT(*_v,value_exc); yyval.ptr = (void *)_v; } break;case 97:#line 325 "snapparse.y"{ value_t *_v; int offs = newtup((list_t *)yyvsp[-1].ptr,__FILE__,__LINE__); free_list(yyvsp[-1].ptr); memalloc(_v,value_t *,sizeof(value_t)); SET_TAG(*_v,TUPLEV); SET_OFFS(*_v,offs); yyval.ptr = (void *)_v; } break;case 98:#line 336 "snapparse.y"{ yyval.ptr = (void *)cons(yyvsp[-2].ptr,(list_t *)yyvsp[0].ptr); } break;case 99:#line 337 "snapparse.y"{ yyval.ptr = (void *)cons(yyvsp[0].ptr,(list_t *)0); } break;case 100:#line 340 "snapparse.y"{ yyval.integer = yyvsp[-2].integer + yyvsp[0].integer; } break;case 101:#line 341 "snapparse.y"{ yyval.integer = yyvsp[-2].integer - yyvsp[0].integer; } break;case 102:#line 342 "snapparse.y"{ yyval.integer = p->pc - p->code_min; } break;case 103:#line 343 "snapparse.y"{ yyval.integer = value_int; } break;case 104:#line 344 "snapparse.y"{ yyval.integer = 0; label = value_str.s; } break;}#line 705 "/usr/share/bison/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 347 "snapparse.y"int newho(buffer_t *b,char *file,int line) { int sizeb = sizeof(heap_obj) + b->lenb; int offs; heap_obj *ho; if ((sizeb & 0x3) != 0) { sizeb = (sizeb & ~0x3) + 4; } if (((p->h_alloc_ptr + sizeb) > p->heap_max) || (b->lenb > MAX_HEAPOBJ_SZ)) { fprintf(stderr,"%s:%d: heap alloc failed\n",file,line); fflush(stderr); exit(1); } ho = (heap_obj *)(p->h_alloc_ptr); offs = p->h_alloc_ptr - p->heap_min; d_printf(150,"%s:%d: alloc %d-string at @%#x, offs = %d\n", __FILE__,__LINE__, b->lenb, p->h_alloc_ptr, offs); p->h_alloc_ptr = p->h_alloc_ptr + sizeb; bzero(ho,sizeb); ho->len = b->lenb; ho->flag = 0; memcpy((char *)(&(ho->s)),b->s,b->lenb); return(offs);}int newtup(list_t *list,char *file,int line) { int len = length_list(list); int lenb = len * sizeof(value_t); int sizeb = sizeof(heap_obj) + lenb; int offs; heap_obj *ho; value_t *varr; list_t *iter; assert ((sizeb & 0x3) == 0); if (((p->h_alloc_ptr + sizeb) > p->heap_max) || (lenb > MAX_HEAPOBJ_SZ)) { fprintf(stderr,"%s:%d: heap alloc failed\n",file,line); fflush(stderr); exit(1); } ho = (heap_obj *)(p->h_alloc_ptr); offs = p->h_alloc_ptr - p->heap_min; d_printf(150,"%s:%d: alloc %d-tuple at @%#x, offs = %d\n", __FILE__,__LINE__, lenb / sizeof(value_t), p->h_alloc_ptr, offs); p->h_alloc_ptr = p->h_alloc_ptr + sizeb; bzero(ho,sizeb); ho->len = lenb; ho->flag = 1; varr = (value_t *)ho->s; for (iter = list; iter != NULL; iter = iter->next, varr++) { *varr = *((value_t *)iter->v); } return(offs);}#ifdef SMALL_INSTRSOPCODE_T refine_op(OPCODE_T op, TAG_T vtag) { switch (op) { case PUSH: switch (vtag) { case INTV: op = PINT; break; case ADDRV: op = PADDR; break; case STRV: op = PSTR; break; case EXCV: op = PEXC; break; case TUPLEV: op = PTUP; break; case FLOATV: op = PFLT; break; default: fprintf(stderr,"%s:%d: invalid tag %d\n",__FILE__,__LINE__,vtag); exit(1); } break; case EQI: switch (vtag) { case INTV: op = EQINT; break; case ADDRV: op = EQADR; break; case STRV: op = EQSTR; break; case EXCV: op = EQEXC; break; case TUPLEV: op = EQTUP; break; case FLOATV: op = EQFLT; break; default: fprintf(stderr,"%s:%d: invalid tag %d\n",__FILE__,__LINE__,vtag); exit(1); } break; case NEQI: switch (vtag) { case INTV: op = NQINT; break; case ADDRV: op = NQADR; break; case STRV: op = NQSTR; break; case EXCV: op = NQEXC; break; case TUPLEV: op = NQTUP; break; case FLOATV: op = NQFLT; break; default: fprintf(stderr,"%s:%d: invalid tag %d\n",__FILE__,__LINE__,vtag); exit(1); } break; case ADDI: switch (vtag) { case INTV: break; case FLOATV: op = FADDI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for ADDI\n", __FILE__,__LINE__,vtag); break; } break; case SUBI: switch (vtag) { case INTV: break; case FLOATV: op = FSUBI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for SUBI\n", __FILE__,__LINE__,vtag); break; } break; case MULTI: switch (vtag) { case INTV: break; case FLOATV: op = FMULI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for MULTI\n", __FILE__,__LINE__,vtag); break; } break; case DIVI: switch (vtag) { case INTV: break; case FLOATV: op = FDIVI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for DIVI\n", __FILE__,__LINE__,vtag); break; } break; case GTI: switch (vtag) { case INTV: break; case FLOATV: op = FGTI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for GTI\n", __FILE__,__LINE__,vtag); break; } break; case GEQI: switch (vtag) { case INTV: break; case FLOATV: op = FGEQI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for GEQI\n", __FILE__,__LINE__,vtag); break; } break; case LTI: switch (vtag) { case INTV: break; case FLOATV: op = FLTI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for LTI\n", __FILE__,__LINE__,vtag); break; } break; case LEQI: switch (vtag) { case INTV: break; case FLOATV: op = FLEQI; break; default: fprintf(stderr,"%s:%d: invalid tag %d for LEQI\n", __FILE__,__LINE__,vtag); break; } break; default: fprintf(stderr,"%s:%d: invalid opcode %d\n",__FILE__,__LINE__,op); exit(1); } return op;}#endifvoid yyerror(char *s) { fprintf(stderr,s);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -