X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/2779e38386a522cb701e1173a8770e86d7bb6c29..b8458aa5ccca039e48c37a3947df3025e3acbcee:/data/yacc.c diff --git a/data/yacc.c b/data/yacc.c index 92c0ddec..f1040ebd 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -1,7 +1,7 @@ m4_divert(-1) -*- C -*- # Yacc compatible skeleton for Bison -# Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 +# Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 # Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify @@ -76,8 +76,8 @@ m4_define([b4_int_type], [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], b4_ints_in($@, [-128], [127]), [1], [yysigned_char], - b4_ints_in($@, [0], [65535]), [1], [unsigned short], - b4_ints_in($@, [-32768], [32767]), [1], [short], + b4_ints_in($@, [0], [65535]), [1], [unsigned short int], + b4_ints_in($@, [-32768], [32767]), [1], [short int], m4_eval([0 <= $1]), [1], [unsigned int], @@ -134,7 +134,7 @@ m4_changecom() m4_divert(0)dnl @output @output_parser_name@ b4_copyright([Skeleton parser for Yacc-like parsing with Bison], - [1984, 1989, 1990, 2000, 2001, 2002, 2003])[ + [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004])[ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. @@ -261,7 +261,7 @@ b4_syncline([@oline@], [@ofile@])[ /* A type that is properly aligned for any stack member. */ union yyalloc { - short yyss; + short int yyss; YYSTYPE yyvs; ]b4_location_if([ YYLTYPE yyls; ])dnl @@ -274,10 +274,10 @@ union yyalloc N elements. */ ]b4_location_if( [# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + ((N) * (sizeof (short int) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM)], [# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM)])[ /* Copy COUNT objects from FROM to TO. The source and destination do @@ -319,7 +319,7 @@ union yyalloc #if defined (__STDC__) || defined (__cplusplus) typedef signed char yysigned_char; #else - typedef short yysigned_char; + typedef short int yysigned_char; #endif /* YYFINAL -- State number of the termination state. */ @@ -501,11 +501,12 @@ do \ } \ while (0) + #define YYTERROR 1 #define YYERRCODE 256 -/* YYLLOC_DEFAULT -- Compute the default location (before the actions - are run). */ + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. */ #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ @@ -515,6 +516,23 @@ while (0) (Current).last_column = (Rhs)[N].last_column) #endif + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# endif +#else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif + + /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM @@ -537,31 +555,25 @@ do { \ YYFPRINTF Args; \ } while (0) -# define YYDSYMPRINT(Args) \ -do { \ - if (yydebug) \ - yysymprint Args; \ -} while (0) - -# define YYDSYMPRINTF(Title, Token, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yysymprint (stderr, \ - Token, Value]b4_location_if([, Location])[); \ + Type, Value]b4_location_if([, Location])[); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (cinluded). | +| TOP (included). | `------------------------------------------------------------------*/ ]b4_c_function_def([yy_stack_print], [static void], - [[short *bottom], [bottom]], - [[short *top], [top]])[ + [[short int *bottom], [bottom]], + [[short int *top], [top]])[ { YYFPRINTF (stderr, "Stack now"); for (/* Nothing. */; bottom <= top; ++bottom) @@ -604,8 +616,7 @@ do { \ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) -# define YYDSYMPRINT(Args) -# define YYDSYMPRINTF(Title, Token, Value, Location) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -713,15 +724,15 @@ m4_divert_push([KILL])# ======================== M4 code. # Declare the variables that are global, or local to YYPARSE if # pure-parser. m4_define([b4_declare_parser_variables], -[/* The lookahead symbol. */ +[/* The look-ahead symbol. */ int yychar; -/* The semantic value of the lookahead symbol. */ +/* The semantic value of the look-ahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs;b4_location_if([ -/* Location data for the lookahead symbol. */ +/* Location data for the look-ahead symbol. */ YYLTYPE yylloc;]) ]) m4_divert_pop([KILL])dnl# ====================== End of M4 code. @@ -751,7 +762,7 @@ b4_c_function_def([yyparse], [int], b4_parse_param) int yyresult; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; - /* Lookahead token as an internal (translated) token number. */ + /* Look-ahead token as an internal (translated) token number. */ int yytoken = 0; /* Three stacks and their tools: @@ -763,9 +774,9 @@ b4_c_function_def([yyparse], [int], b4_parse_param) to reallocate them elsewhere. */ /* The state stack. */ - short yyssa[YYINITDEPTH]; - short *yyss = yyssa; - register short *yyssp; + short int yyssa[YYINITDEPTH]; + short int *yyss = yyssa; + register short int *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; @@ -777,7 +788,8 @@ b4_c_function_def([yyparse], [int], b4_parse_param) YYLTYPE yylsa[YYINITDEPTH]; YYLTYPE *yyls = yylsa; YYLTYPE *yylsp; - YYLTYPE *yylerrsp;]])[ + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[2];]])[ #define YYPOPSTACK (yyvsp--, yyssp--]b4_location_if([, yylsp--])[) @@ -806,8 +818,24 @@ b4_c_function_def([yyparse], [int], b4_parse_param) yyssp = yyss; yyvsp = yyvs; -]b4_location_if([ yylsp = yyls;])[ - goto yysetstate; +]b4_location_if([[ yylsp = yyls; +#if YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yyls[0].first_line = yyls[0].last_line = 1; + yyls[0].first_column = yyls[0].last_column = 0; +#endif +]]) +m4_ifdef([b4_initial_action], [ +m4_pushdef([b4_at_dollar], [(*yylsp)])dnl +m4_pushdef([b4_dollar_dollar], [(*yyvsp)])dnl + /* User initialization code. */ + b4_initial_action +m4_popdef([b4_dollar_dollar])dnl +m4_popdef([b4_at_dollar])dnl +/* Line __line__ of yacc.c. */ +b4_syncline([@oline@], [@ofile@])])dnl + +[ goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | @@ -832,7 +860,7 @@ b4_c_function_def([yyparse], [int], b4_parse_param) these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; + short int *yyss1 = yyss; ]b4_location_if([ YYLTYPE *yyls1 = yyls;])[ /* Each stack pointer address is followed by the size of the @@ -860,7 +888,7 @@ b4_c_function_def([yyparse], [int], b4_parse_param) yystacksize = YYMAXDEPTH; { - short *yyss1 = yyss; + short int *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) @@ -896,18 +924,18 @@ b4_c_function_def([yyparse], [int], b4_parse_param) yybackup: /* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ +/* Read a look-ahead token if we need one and don't already have one. */ /* yyresume: */ - /* First try to decide what to do without reference to lookahead token. */ + /* First try to decide what to do without reference to look-ahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; - /* Not known => get a lookahead token if don't already have one. */ + /* Not known => get a look-ahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); @@ -922,7 +950,7 @@ yybackup: else { yytoken = YYTRANSLATE (yychar); - YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to @@ -942,8 +970,8 @@ yybackup: if (yyn == YYFINAL) YYACCEPT; - /* Shift the lookahead token. */ - YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) @@ -989,8 +1017,11 @@ yyreduce: yyval = yyvsp[1-yylen]; ]b4_location_if( -[ /* Default location. */ - YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);])[ +[[ /* Default location. */ + if (yylen) + YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen); + else + yyloc = yylsp[0];]])[ YY_REDUCE_PRINT (yyn); switch (yyn) ]{ @@ -1094,11 +1125,11 @@ yyerrlab: yyerror (]b4_yyerror_args["syntax error"); } -]b4_location_if([ yylerrsp = yylsp;])[ +]b4_location_if([[ yyerror_range[0] = yylloc;]])[ if (yyerrstatus == 3) { - /* If just tried and failed to reuse lookahead token after an + /* If just tried and failed to reuse look-ahead token after an error, discard it. */ if (yychar <= YYEOF) @@ -1108,23 +1139,22 @@ yyerrlab: if (yychar == YYEOF) for (;;) { +]b4_location_if([[ yyerror_range[0] = *yylsp;]])[ YYPOPSTACK; if (yyssp == yyss) YYABORT; - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[); + yydestruct ("Error: popping", + yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[); } } else { - YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); - yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[); + yydestruct ("Error: discarding", yytoken, &yylval]b4_location_if([, &yylloc])[); yychar = YYEMPTY; -]b4_location_if([ *++yylerrsp = yylloc;])[ } } - /* Else will try to reuse lookahead token after shifting the error + /* Else will try to reuse look-ahead token after shifting the error token. */ goto yyerrlab1; @@ -1141,13 +1171,12 @@ yyerrorlab: goto yyerrorlab; #endif - yyvsp -= yylen; +]b4_location_if([[ yyerror_range[0] = yylsp[1-yylen]; + yylsp -= yylen; + ]])[yyvsp -= yylen; yyssp -= yylen; yystate = *yyssp; - ]b4_location_if([yylerrsp = yylsp; - *++yylerrsp = yyloc; - yylsp -= yylen; - ])[goto yyerrlab1; + goto yyerrlab1; /*-------------------------------------------------------------. @@ -1174,8 +1203,8 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[yystate], yyvsp]b4_location_if([, yylsp])[); +]b4_location_if([[ yyerror_range[0] = *yylsp;]])[ + yydestruct ("Error: popping", yystos[yystate], yyvsp]b4_location_if([, yylsp])[); YYPOPSTACK; yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1184,11 +1213,16 @@ yyerrlab1: if (yyn == YYFINAL) YYACCEPT; - YYDPRINTF ((stderr, "Shifting error token, ")); - *++yyvsp = yylval; -]b4_location_if([ YYLLOC_DEFAULT (yyloc, yylsp, yylerrsp - yylsp); - *++yylsp = yyloc;])[ +]b4_location_if([[ + yyerror_range[1] = yylloc; + /* Using YYLLOC is tempting, but would change the location of + the look-ahead. YYLOC is available though. */ + YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2); + *++yylsp = yyloc;]])[ + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -1205,6 +1239,9 @@ yyacceptlab: | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: + yydestruct ("Error: discarding lookahead", + yytoken, &yylval]b4_location_if([, &yylloc])[); + yychar = YYEMPTY; yyresult = 1; goto yyreturn; @@ -1231,7 +1268,7 @@ b4_epilogue m4_if(b4_defines_flag, 0, [], [@output @output_header_name@ b4_copyright([Skeleton parser for Yacc-like parsing with Bison], - [1984, 1989, 1990, 2000, 2001, 2002, 2003]) + [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004]) /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction.