📄 parse.c
字号:
void format_pinpoint_message( msg, arg )char msg[], arg[]; { char errmsg[MAXLINE]; (void) sprintf( errmsg, msg, arg ); pinpoint_message( errmsg ); }/* pinpoint_message - write out a message, pinpointing its location */void pinpoint_message( str )char str[]; { line_pinpoint( str, linenum ); }/* line_warning - report a warning at a given line, unless -w was given */void line_warning( str, line )char str[];int line; { char warning[MAXLINE]; if ( ! nowarn ) { sprintf( warning, "warning, %s", str ); line_pinpoint( warning, line ); } }/* line_pinpoint - write out a message, pinpointing it at the given line */void line_pinpoint( str, line )char str[];int line; { fprintf( stderr, "\"%s\", line %d: %s\n", infilename, line, str ); }/* yyerror - eat up an error message from the parser; * currently, messages are ignore */void yyerror( msg )char msg[]; { }#line 541 "y.tab.c"#define YYABORT goto yyabort#define YYREJECT goto yyabort#define YYACCEPT goto yyaccept#define YYERROR goto yyerrlabintyyparse(){ register int yym, yyn, yystate;#if YYDEBUG register char *yys; extern char *getenv(); if (yys = getenv("YYDEBUG")) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; }#endif yynerrs = 0; yyerrflag = 0; yychar = (-1); yyssp = yyss; yyvsp = yyvs; *yyssp = yystate = 0;yyloop: if (yyn = yydefred[yystate]) goto yyreduce; 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("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, yystate, yychar, yys); }#endif } if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) {#if YYDEBUG if (yydebug) printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]);#endif if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; yychar = (-1); if (yyerrflag > 0) --yyerrflag; goto yyloop; } if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag) goto yyinrecovery;#ifdef lint goto yynewerror;#endifyynewerror: yyerror("syntax error");#ifdef lint goto yyerrlab;#endifyyerrlab: ++yynerrs;yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) {#if YYDEBUG if (yydebug) printf("%sdebug: state %d, error recovery shifting\ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);#endif if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; goto yyloop; } else {#if YYDEBUG if (yydebug) printf("%sdebug: error recovery discarding state %d\n", YYPREFIX, *yyssp);#endif if (yyssp <= yyss) goto yyabort; --yyssp; --yyvsp; } } } else { if (yychar == 0) goto yyabort;#if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, error recovery discards token %d (%s)\n", YYPREFIX, yystate, yychar, yys); }#endif yychar = (-1); goto yyloop; }yyreduce:#if YYDEBUG if (yydebug) printf("%sdebug: state %d, reducing by rule %d (%s)\n", YYPREFIX, yystate, yyn, yyrule[yyn]);#endif yym = yylen[yyn]; yyval = yyvsp[1-yym]; switch (yyn) {case 1:#line 113 "./parse.y"{ /* add default rule */ int def_rule; pat = cclinit(); cclnegate( pat ); def_rule = mkstate( -pat ); /* Remember the number of the default rule so we * don't generate "can't match" warnings for it. */ default_rule = num_rules; finish_rule( def_rule, false, 0, 0 ); for ( i = 1; i <= lastsc; ++i ) scset[i] = mkbranch( scset[i], def_rule ); if ( spprdflt ) add_action( "YY_FATAL_ERROR( \"flex scanner jammed\" )" ); else add_action( "ECHO" ); add_action( ";\n\tYY_BREAK\n" ); }break;case 2:#line 142 "./parse.y"{ /* initialize for processing rules */ /* Create default DFA start condition. */ scinstal( "INITIAL", false ); }break;case 6:#line 153 "./parse.y"{ synerr( "unknown error processing section 1" ); }break;case 7:#line 157 "./parse.y"{ check_options(); scon_stk = allocate_integer_array( lastsc + 1 ); scon_stk_ptr = 0; }break;case 8:#line 165 "./parse.y"{ xcluflg = false; }break;case 9:#line 168 "./parse.y"{ xcluflg = true; }break;case 10:#line 172 "./parse.y"{ scinstal( nmstr, xcluflg ); }break;case 11:#line 175 "./parse.y"{ scinstal( nmstr, xcluflg ); }break;case 12:#line 178 "./parse.y"{ synerr( "bad start condition list" ); }break;case 16:#line 189 "./parse.y"{ outfilename = copy_string( nmstr ); did_outfilename = 1; }break;case 17:#line 194 "./parse.y"{ prefix = copy_string( nmstr ); }break;case 18:#line 196 "./parse.y"{ yyclass = copy_string( nmstr ); }break;case 19:#line 200 "./parse.y"{ scon_stk_ptr = yyvsp[-3]; }break;case 20:#line 202 "./parse.y"{ scon_stk_ptr = yyvsp[-3]; }break;case 22:#line 207 "./parse.y"{ /* Initialize for a parse of one rule. */ trlcontxt = variable_trail_rule = varlength = false; trailcnt = headcnt = rulelen = 0; current_state_type = STATE_NORMAL; previous_continued_action = continued_action; in_rule = true; new_rule(); }break;case 23:#line 220 "./parse.y"{ pat = yyvsp[0]; finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); if ( scon_stk_ptr > 0 ) { for ( i = 1; i <= scon_stk_ptr; ++i ) scbol[scon_stk[i]] = mkbranch( scbol[scon_stk[i]], pat ); } else { /* Add to all non-exclusive start conditions, * including the default (0) start condition. */ for ( i = 1; i <= lastsc; ++i ) if ( ! scxclu[i] ) scbol[i] = mkbranch( scbol[i], pat ); } if ( ! bol_needed ) { bol_needed = true; if ( performance_report > 1 ) pinpoint_message( "'^' operator results in sub-optimal performance" ); } }break;case 24:#line 256 "./parse.y"{ pat = yyvsp[0]; finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); if ( scon_stk_ptr > 0 ) { for ( i = 1; i <= scon_stk_ptr; ++i ) scset[scon_stk[i]] = mkbranch( scset[scon_stk[i]], pat ); } else { for ( i = 1; i <= lastsc; ++i ) if ( ! scxclu[i] ) scset[i] = mkbranch( scset[i], pat ); } }break;case 25:#line 280 "./parse.y"{ if ( scon_stk_ptr > 0 ) build_eof_action(); else { /* This EOF applies to all start conditions * which don't already have EOF actions. */ for ( i = 1; i <= lastsc; ++i ) if ( ! sceof[i] ) scon_stk[++scon_stk_ptr] = i; if ( scon_stk_ptr == 0 ) warn( "all start conditions already have <<EOF>> rules" ); else build_eof_action(); } }break;case 26:#line 303 "./parse.y"{ synerr( "unrecognized rule" ); }break;case 27:#line 307 "./parse.y"{ yyval = scon_stk_ptr; }break;case 28:#line 311 "./parse.y"{ yyval = yyvsp[-2]; }break;case 29:#line 314 "./parse.y"{ yyval = scon_stk_ptr; for ( i = 1; i <= lastsc; ++i ) { int j; for ( j = 1; j <= scon_stk_ptr; ++j ) if ( scon_stk[j] == i ) break; if ( j > scon_stk_ptr ) scon_stk[++scon_stk_ptr] = i; } }break;case 30:#line 331 "./parse.y"{ yyval = scon_stk_ptr; }break;case 33:#line 339 "./parse.y"{ synerr( "bad start condition list" ); }break;case 34:#line 343 "./parse.y"{ if ( (scnum = sclookup( nmstr )) == 0 ) format_pinpoint_message( "undeclared start condition %s", nmstr ); else { for ( i = 1; i <= scon_stk_ptr; ++i ) if ( scon_stk[i] == scnum ) { format_warn( "<%s> specified twice", scname[scnum] ); break; } if ( i > scon_stk_ptr ) scon_stk[++scon_stk_ptr] = scnum; } }break;case 35:#line 366 "./parse.y"{ if ( transchar[lastst[yyvsp[0]]] != SYM_EPSILON ) /* Provide final transition \now/ so it * will be marked as a trailing context * state. */ yyvsp[0] = link_machines( yyvsp[0], mkstate( SYM_EPSILON ) ); mark_beginning_as_normal( yyvsp[0] ); current_state_type = STATE_NORMAL; if ( previous_continued_action ) { /* We need to treat this as variable trailing * context so that the backup does not happen * in the action but before the action switch * statement. If the backup happens in the * action, then the rules "falling into" this * one's action will *also* do the backup, * erroneously. */ if ( ! varlength || headcnt != 0 ) warn( "trailing context made variable due to preceding '|' action" ); /* Mark as variable. */ varlength = true; headcnt = 0; } if ( lex_compat || (varlength && headcnt == 0) ) { /* variable trailing context rule */ /* Mark the first part of the rule as the * accepting "head" part of a trailing * context rule.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -