?? risk-parser.c
字號:
/* 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];#if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ if (yydebug) { int yyi; YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", yyn - 1, yyrline[yyn]); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyn]; yyrhs[yyi] >= 0; yyi++) YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]); }#endif switch (yyn) { case 5:#line 87 "risk-parser.y" { add_cat_name(yyvsp[0].strval); } break; case 6:#line 88 "risk-parser.y" { add_cat_name(yyvsp[0].strval); } break; case 8:#line 94 "risk-parser.y" { add_prior_weight(yyvsp[0].numval); } break; case 9:#line 95 "risk-parser.y" { add_prior_weight(yyvsp[0].numval); } break; case 11:#line 101 "risk-parser.y" { attach_cat_vec(yyvsp[-1].strval,yyvsp[-2].strval,yyvsp[0].strval); } break; case 12:#line 102 "risk-parser.y" { attach_cat_vec(yyvsp[-1].strval,yyvsp[-2].strval,yyvsp[0].strval); } break; case 13:#line 105 "risk-parser.y" { set_loss_and_increment(yyvsp[0].numval); } break; case 14:#line 106 "risk-parser.y" { set_loss_and_increment(yyvsp[0].numval); } break; case 15:#line 109 "risk-parser.y" { yyval.numval = yyvsp[0].numval; } break; case 16:#line 110 "risk-parser.y" { yyval.numval = spec.loss_list[x]->sm[(int)yyvsp[0].numval]; } break; case 17:#line 111 "risk-parser.y" { yyval.numval = spec.complexity[x]; } break; case 18:#line 112 "risk-parser.y" { yyval.numval = yyvsp[-2].numval + yyvsp[0].numval; } break; case 19:#line 113 "risk-parser.y" { yyval.numval = yyvsp[-2].numval - yyvsp[0].numval; } break; case 20:#line 114 "risk-parser.y" { yyval.numval = yyvsp[-2].numval * yyvsp[0].numval; } break; case 21:#line 115 "risk-parser.y" { yyval.numval = yyvsp[-2].numval / yyvsp[0].numval; } break; case 22:#line 116 "risk-parser.y" { yyval.numval = pow(yyvsp[-2].numval,yyvsp[0].numval); } break; case 23:#line 117 "risk-parser.y" { yyval.numval = yyvsp[-1].numval; } break; case 24:#line 118 "risk-parser.y" { yyval.numval = exp(yyvsp[-1].numval); } break; case 25:#line 119 "risk-parser.y" { yyval.numval = log(yyvsp[-1].numval); } break; }/* Line 1016 of /usr/share/bison/yacc.c. */#line 1124 "y.tab.c" yyvsp -= yylen; yyssp -= yylen;#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; /* 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); 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 && yyx != YYTERROR) yysize += yystrlen (yytname[yyx]) + 15, yycount++; yysize += yystrlen ("parse error, unexpected ") + 1; yysize += yystrlen (yytname[yytype]); yymsg = (char *) YYSTACK_ALLOC (yysize); if (yymsg != 0) { char *yyp = yystpcpy (yymsg, "parse error, unexpected "); yyp = yystpcpy (yyp, yytname[yytype]); if (yycount < 5) { yycount = 0; for (yyx = yyn < 0 ? -yyn : 0; yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { 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 /* 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) { /* Pop the error token. */ YYPOPSTACK; /* Pop the rest of the stack. */ while (yyssp > yyss) { YYDPRINTF ((stderr, "Error: popping ")); YYDSYMPRINT ((stderr, yystos[*yyssp], *yyvsp)); YYDPRINTF ((stderr, "\n")); yydestruct (yystos[*yyssp], *yyvsp); YYPOPSTACK; } YYABORT; } YYDPRINTF ((stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1])); yydestruct (yychar1, yylval); yychar = YYEMPTY; } /* Else will try to reuse lookahead token after shifting the error token. */ 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; YYDPRINTF ((stderr, "Error: popping ")); YYDSYMPRINT ((stderr, yystos[*yyssp], *yyvsp)); YYDPRINTF ((stderr, "\n")); yydestruct (yystos[yystate], *yyvsp); yyvsp--; yystate = *--yyssp;#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 } 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 122 "risk-parser.y"void set_loss_and_increment(real_value_t v) { if( v < 0.0 ) { fprintf(stderr, "error: negative losses not supported (%s,%s)\n", spec.catname[x], spec.catname[y]); exit(0); } else { spec.loss_matrix[x][y++] = log(v); }}int parse_loss_vec(category_count_t i, char *buf) { int result;#if YYDEBUG yydebug = 1;#endif reset_lexer(); x = i; y = 0; lexer_prepare_string(buf); result = yyparse(); lexer_free_string(); return result;}int parse_risk_spec(FILE *input) {#if YYDEBUG yydebug = 1;#endif yyin = input; reset_lexer(); return yyparse();}int yyerror(char *s){ fprintf(stderr, "parse error at line %d before '%s'\n", current_lineno, yytext); return 0;}void add_prior_weight(real_value_t w) { if( w < 0.0 ) { fprintf(stderr, "error: prior can't have negative values (%f)\n", w); exit(0); } else if(spec.num_priors < MAX_CAT) { spec.prior[spec.num_priors++] = log(w); } else { fprintf(stderr, "warning: maximum reached, prior weight ignored\n"); }}void add_cat_name(char *n) { if(spec.num_cats < MAX_CAT) { spec.catname[spec.num_cats++] = n; } else { fprintf(stderr, "warning: maximum reached, category ignored\n"); } }void attach_cat_vec(char *n, char *r, char *v) { category_count_t i; LossVector *p, *q; /* see if category name is known */ for( i = 0; i < spec.num_cats; i++ ) { if( strcmp(spec.catname[i], n) == 0 ) { break; } } if( i < spec.num_cats ) { /* create a new LossVector */ p = malloc(sizeof(LossVector)); if( p ) { p->re = r; p->ve = v; p->next = NULL; } else { fprintf(stderr, "error: couldn't allocate memory needed for loss matrix\n"); yyerror(NULL); } /* add this vector spec to the appropriate list */ if( spec.loss_list[i] == NULL ) { spec.loss_list[i] = p; } else { for(q = spec.loss_list[i]; q->next != NULL; q = q->next); q->next = p; } } else { fprintf(stderr, "error: encountered unknown category\n"); yyerror(NULL); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -