Index: data/yacc.c --- data/yacc.c Sun, 27 Oct 2002 13:07:36 +0100 akim +++ data/yacc.c Sat, 02 Nov 2002 17:58:03 +0100 akim @@ -33,6 +33,39 @@ m4_define_default([b4_stack_depth_init], # Location type. m4_define_default([b4_location_type], [yyltype]) + +## ------------------------ ## +## Pure/impure interfaces. ## +## ------------------------ ## + +# b4_Pure_if(IF-YEP, IF-NOPE) +# --------------------------- +# If we are *really* pure, expand IF-YEP, otherwise IF-NOPE. +# "Really pure" means that 1. we are %pure-parser, and 2. %parse-param +# is used. This is to cope with backward compatibility where users +# could have a pure parser, but no means to make yyerror pure, so they +# used tricks, which are incompatible with our new pure handling of yyerror. +m4_define([b4_Pure_if], +[b4_pure_if([m4_ifset([b4_parse_param], + [$1], [$2])], + [$2])]) + + +# b4_user_args +# ------------ +m4_define([b4_user_args], +[m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])]) + + +# b4_pure_args +# ------------ +# Arguments passed to yyerror: user args plus yylloc. +m4_define([b4_pure_args], +[b4_pure_if([b4_location_if([, &yylloc])])[]b4_user_args]) + + +# b4_lex_param +# ------------ # Accumule in b4_lex_param all the yylex arguments. # Yes, this is quite ugly... m4_define([b4_lex_param], @@ -40,12 +73,14 @@ m4_define([b4_lex_param], b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl m4_ifdef([b4_lex_param], [, ]b4_lex_param))) -# Yes, this is quite ugly... -m4_define_default([b4_parse_param]) -m4_ifdef([b4_parse_param], -[m4_define([b4_parse_param], - b4_parse_param)]) +# b4_parse_param +# -------------- +# If defined, b4_parse_param arrives double quoted, but below we prefer +# it to be single quoted. +m4_define_default([b4_parse_param]) +m4_define([b4_parse_param], + b4_parse_param)) ## ------------ ## @@ -56,7 +91,7 @@ m4_define_default([b4_parse_param]) # --------------------- # Return the smallest int type able to handle numbers ranging from # MIN to MAX (included). We overwrite the version from c.m4 which relies -# on `signed char' which is not portable to old K&R compilers. +# on "signed char" which is not portable to old K&R compilers. m4_define([b4_int_type], [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], b4_ints_in($@, [-128], [127]), [1], [yysigned_char], @@ -178,15 +213,7 @@ m4_define([b4_symbol_actions], define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Identify Bison output. */ -#define YYBISON 1 - -/* Pure parsers. */ -#define YYPURE b4_pure - -/* Using locations. */ -#define YYLSP_NEEDED b4_locations_flag - +b4_identification m4_if(b4_prefix[], [yy], [], [/* If NAME_PREFIX is specified substitute the variables and functions names. */ @@ -519,7 +546,7 @@ m4_define([b4_symbol_actions], } \ else \ { \ - yyerror ("syntax error: cannot back up"); \ + yyerror ("syntax error: cannot back up"b4_pure_args); \ YYERROR; \ } \ while (0) @@ -1125,15 +1152,15 @@ yyerrlab: yycount++; } } - yyerror (yymsg); + yyerror (yymsg]b4_pure_args[); YYSTACK_FREE (yymsg); } else - yyerror ("parse error; also virtual memory exhausted"); + yyerror ("parse error; also virtual memory exhausted"]b4_pure_args[); } else #endif /* YYERROR_VERBOSE */ - yyerror ("parse error"); + yyerror ("parse error"]b4_pure_args[); } goto yyerrlab1; @@ -1248,7 +1275,7 @@ yyabortlab: | yyoverflowlab -- parser overflow comes here. | `----------------------------------------------*/ yyoverflowlab: - yyerror ("parser stack overflow"); + yyerror ("parser stack overflow"]b4_pure_args[); yyresult = 2; /* Fall through. */ #endif Index: data/c.m4 --- data/c.m4 Sun, 27 Oct 2002 13:07:36 +0100 akim +++ data/c.m4 Sat, 02 Nov 2002 17:23:59 +0100 akim @@ -19,9 +19,9 @@ # 02111-1307 USA -## ----------- ## -## Copyright. ## -## ----------- ## +## ---------------- ## +## Identification. ## +## ---------------- ## # b4_copyright(TITLE, YEARS) # -------------------------- @@ -45,6 +45,28 @@ m4_define([b4_copyright], along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */]) + + +# b4_identification +# ----------------- +m4_define([b4_identification], +[/* Identify Bison output. */ +[#]define YYBISON 1 + +/* Skeleton name. */ +[#]define YYSKELETON_NAME "b4_skeleton" + +/* Skeleton token. */ +[#]define YYSKELETON m4_bpatsubst(m4_toupper(b4_skeleton), + [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_]) + +/* Pure parsers. */ +[#]define YYPURE b4_pure + +/* Using locations. */ +[#]define YYLSP_NEEDED b4_locations_flag +]) + ## ------------ ## Index: data/glr.c --- data/glr.c Wed, 30 Oct 2002 07:55:03 +0100 akim +++ data/glr.c Sat, 02 Nov 2002 17:55:38 +0100 akim @@ -31,6 +31,15 @@ m4_define_default([b4_stack_depth_init], # Location type. m4_define_default([b4_location_type], [yyltype]) + + +## ------------------------ ## +## Pure/impure interfaces. ## +## ------------------------ ## + + +# b4_lex_param +# ------------ # Accumule in b4_lex_param all the yylex arguments. # Yes, this is quite ugly... m4_define([b4_lex_param], @@ -38,13 +47,63 @@ m4_define([b4_lex_param], b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl m4_ifdef([b4_lex_param], [, ]b4_lex_param))) -# Yes, this is quite ugly... - m4_define_default([b4_parse_param]) -m4_ifdef([b4_parse_param], -[m4_define([b4_parse_param], - b4_parse_param)]) + +# b4_parse_param +# -------------- +# If defined, b4_parse_param arrives double quoted, but below we prefer +# it to be single quoted. +m4_define_default([b4_parse_param]) +m4_define([b4_parse_param], + b4_parse_param)) + + +# b4_user_args +# ------------ +m4_define([b4_user_args], +[m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])]) + + +# b4_user_formals +# --------------- +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) + + +# b4_pure_args +# ------------ +# Arguments passed to yyerror: user args plus yylloc. +m4_define([b4_pure_args], +[b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args]) + + +# b4_pure_formals +# --------------- +# Arguments passed to yyerror: user formals plus yyllocp. +m4_define([b4_pure_formals], +[b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals]) + + +# b4_lpure_args +# ------------- +# Same as above, but on the lookahead, hence yyllocp instead of yylocp. +m4_define([b4_lpure_args], +[b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args]) + + +# b4_lpure_formals +# ---------------- +# Same as above, but on the lookahead, hence yyllocp instead of yylocp. +m4_define([b4_lpure_formals], +[b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals]) +# b4_yyFail(STACK, FORMAT, ARGS) +# ------------------------------ +# Expands to an yyFail call with FORMAT and ARGS as arguments, +# but also with everything that is needed for the purity. +m4_define([b4_yyFail], +[yyFail ([$1]b4_pure_args, m4_shift($@))]) + ## ----------------- ## ## Semantic Values. ## @@ -119,24 +178,15 @@ m4_define_default([b4_header_guard], [ /* This is the parser code for GLR (Generalized LR) parser. */ -/* FIXME: minimize these */ #include -#include -#include #include #include #include +#include +#include -/* Identify Bison output. */ -#define YYBISON 1 - -/* Pure parsers. */ -#define YYPURE ]b4_pure[ - -/* Using locations. */ -#define YYLSP_NEEDED ]b4_locations_flag[ - -]m4_if(b4_prefix[], [yy], [], +]b4_identification +m4_if(b4_prefix[], [yy], [], [/* If NAME_PREFIX is specified substitute the variables and functions names. */ #define yyparse b4_prefix[]parse @@ -378,16 +428,9 @@ m4_define_default([b4_header_guard], /* Prevent warning if -Wmissing-prototypes. */ -]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param) - -m4_ifset([b4_parse_param], -[#define YY_USER_FORMALS , b4_c_ansi_formals(b4_parse_param) -#define YY_USER_ARGS , b4_c_args(b4_parse_param)], -[#define YY_USER_FORMALS -#define YY_USER_ARGS]) +]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[ - -[/* Error token number */ +/* Error token number */ #define YYTERROR 1 /* YYLLOC_DEFAULT -- Compute the default location (before the actions @@ -548,24 +591,27 @@ m4_define_default([b4_header_guard], }; static void yyinitGLRStack (yyGLRStack* yystack, size_t yysize); -static void yyexpandGLRStack (yyGLRStack* yystack); +static void yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[); static void yyfreeGLRStack (yyGLRStack* yystack); static void -yyFail (yyGLRStack* yystack, const char* yyformat, ...) +yyCut (yyGLRStack* yystack) { - if (yyformat != NULL) - { - char yymsg[256]; - va_list yyap; - va_start (yyap, yyformat); - yystack->yyerrflag = 1; - vsprintf (yymsg, yyformat, yyap); - yyerror (yymsg); - } longjmp (yystack->yyexception_buffer, 1); } +static void +yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...) +{ + char yymsg[256]; + va_list yyap; + va_start (yyap, yyformat); + yystack->yyerrflag = 1; + vsprintf (yymsg, yyformat, yyap); + yyerror (yymsg]b4_pure_args[); + yyCut (yystack); +} + #if YYDEBUG || YYERROR_VERBOSE /** A printable representation of TOKEN. Valid until next call to * tokenName. */ @@ -584,7 +630,7 @@ m4_define_default([b4_header_guard], static YYRESULTTAG yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack - YY_USER_FORMALS) + ]b4_user_formals[) { /* Avoid `unused' warnings in there are no $n. */ (void) yystack; @@ -616,7 +662,7 @@ m4_define_default([b4_header_guard], # undef YYBACKUP # define YYBACKUP(Token, Value) \ do { \ - yyerror ("syntax error: cannot back up"); \ + yyerror ("syntax error: cannot back up"]b4_pure_args[); \ YYERROR; \ } while (0) @@ -751,7 +797,7 @@ m4_define_default([b4_header_guard], static void yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate, - yyGLRState* rhs, yyRuleNum yyrule) + yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[) { yySemanticOption* yynewItem; yynewItem = &yystack->yynextFree->yyoption; @@ -763,7 +809,7 @@ m4_define_default([b4_header_guard], yynewItem->yynext = yystate->yysemantics.yyfirstVal; yystate->yysemantics.yyfirstVal = yynewItem; if (yystack->yyspaceLeft < YYHEADROOM) - yyexpandGLRStack (yystack); + yyexpandGLRStack (yystack]b4_pure_args[); } /* GLRStacks */ @@ -808,7 +854,7 @@ m4_define_default([b4_header_guard], allocation, so that we can avoid having external pointers exist across an allocation. */ static void -yyexpandGLRStack (yyGLRStack* yystack) +yyexpandGLRStack (yyGLRStack* yystack]b4_pure_formals[) { #if YYSTACKEXPANDABLE yyGLRStack yynewStack; @@ -817,7 +863,7 @@ m4_define_default([b4_header_guard], size_t yyn; yysize = yystack->yynextFree - yystack->yyitems; if (YYMAXDEPTH <= yysize) - yyFail (yystack, "parsing stack overflow (%d items)", yysize); + ]b4_yyFail(yystack, "parsing stack overflow (%d items)", yysize)[; yynewSize = 2*yysize; if (YYMAXDEPTH < yynewSize) yynewSize = YYMAXDEPTH; @@ -864,8 +910,7 @@ m4_define_default([b4_header_guard], #else - yyFail (yystack, "parsing stack overflow (%d items)", yysize); - + ]b4_yyFail(yystack, "parsing stack overflow (%d items)", yysize)[; #endif } @@ -937,7 +982,7 @@ m4_define_default([b4_header_guard], * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */ static inline void yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn, - YYSTYPE yysval, YYLTYPE* yylocp) + YYSTYPE yysval, YYLTYPE* yylocp]b4_user_formals[) { yyGLRStackItem* yynewItem; @@ -953,7 +998,7 @@ m4_define_default([b4_header_guard], yynewItem->yystate.yysemantics.yysval = yysval; yynewItem->yystate.yyloc = *yylocp; if (yystack->yyspaceLeft < YYHEADROOM) - yyexpandGLRStack (yystack); + yyexpandGLRStack (yystack]b4_pure_args[); } /** Shift to a new state on stack #K of STACK, to a new state @@ -961,7 +1006,7 @@ m4_define_default([b4_header_guard], * the (unresolved) semantic value of RHS under the action for RULE. */ static inline void yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState, - size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule) + size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule]b4_pure_formals[) { yyGLRStackItem* yynewItem; @@ -975,7 +1020,7 @@ m4_define_default([b4_header_guard], yystack->yytops.yystates[yyk] = &yynewItem->yystate; yystack->yynextFree += 1; yystack->yyspaceLeft -= 1; - yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule); + yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule]b4_pure_args[); } /** Pop the symbols consumed by reduction #RULE from the top of stack @@ -986,7 +1031,7 @@ m4_define_default([b4_header_guard], * for userAction. */ static inline int yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, - YYSTYPE* yyvalp, YYLTYPE* yylocp YY_USER_FORMALS) + YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) { int yynrhs = yyrhsLength (yyrule); @@ -1009,7 +1054,7 @@ m4_define_default([b4_header_guard], *yylocp = rhs[1-yynrhs].yystate.yyloc; } return yyuserAction (yyrule, yynrhs, rhs, - yyvalp, yylocp, yystack YY_USER_ARGS); + yyvalp, yylocp, yystack]b4_user_args[); } else { @@ -1037,7 +1082,7 @@ m4_define_default([b4_header_guard], *yylocp = yyrhsVals[0].yystate.yyloc; } return yyuserAction (yyrule, yynrhs, yyrhsVals + (yynrhs-1), - yyvalp, yylocp, yystack YY_USER_ARGS); + yyvalp, yylocp, yystack]b4_user_args[); } } @@ -1080,7 +1125,7 @@ m4_define_default([b4_header_guard], */ static inline YYRESULTTAG yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, - bool yyforceEval YY_USER_FORMALS) + bool yyforceEval]b4_pure_formals[) { size_t yyposn = yystack->yytops.yystates[yyk]->yyposn; @@ -1090,11 +1135,11 @@ m4_define_default([b4_header_guard], YYLTYPE yyloc; YY_REDUCE_PRINT (yyk, yyrule); - YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc YY_USER_ARGS)); + YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); yyglrShift (yystack, yyk, yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState, yylhsNonterm (yyrule)), - yyposn, yysval, &yyloc); + yyposn, yysval, &yyloc]b4_user_args[); YYDPRINTF ((stderr, "Stack %d entering state %d\n", yyk, yystack->yytops.yystates[yyk]->yylrState)); } @@ -1126,7 +1171,7 @@ m4_define_default([b4_header_guard], { if (yyp->yylrState == yynewLRState && yyp->yypred == yys) { - yyaddDeferredAction (yystack, yyp, yys0, yyrule); + yyaddDeferredAction (yystack, yyp, yys0, yyrule]b4_pure_args[); yymarkStackDeleted (yystack, yyk); YYDPRINTF ((stderr, "Merging stack %d into stack %d.\n", yyk, yyi)); @@ -1136,7 +1181,7 @@ m4_define_default([b4_header_guard], } } yystack->yytops.yystates[yyk] = yys; - yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule); + yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule]b4_pure_args[); } return 0; } @@ -1236,23 +1281,23 @@ m4_define_default([b4_header_guard], static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack, YYSTYPE* yyvalp, - YYLTYPE* yylocp YY_USER_FORMALS); + YYLTYPE* yylocp]b4_user_formals[); static YYRESULTTAG -yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack YY_USER_FORMALS) +yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[) { YYRESULTTAG yyflag; if (0 < yyn) { assert (yys->yypred != NULL); - yyflag = yyresolveStates (yys->yypred, yyn-1, yystack YY_USER_ARGS); + yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[); if (yyflag != yyok) return yyflag; if (! yys->yyresolved) { yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack, &yys->yysemantics.yysval, &yys->yyloc - YY_USER_ARGS); + ]b4_user_args[); if (yyflag != yyok) return yyflag; yys->yyresolved = yytrue; @@ -1263,14 +1308,14 @@ m4_define_default([b4_header_guard], static YYRESULTTAG yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack, - YYSTYPE* yyvalp, YYLTYPE* yylocp YY_USER_FORMALS) + YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) { yyGLRStackItem yyrhsVals[YYMAXRHS]; int yynrhs, yyi; yyGLRState* yys; yynrhs = yyrhsLength (yyopt->yyrule); - YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack YY_USER_ARGS)); + YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[)); for (yyi = yynrhs-1, yys = yyopt->yystate; 0 <= yyi; yyi -= 1, yys = yys->yypred) { @@ -1280,7 +1325,7 @@ m4_define_default([b4_header_guard], yyrhsVals[yyi].yystate.yyloc = yys->yyloc; } return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + (yynrhs-1), - yyvalp, yylocp, yystack YY_USER_ARGS); + yyvalp, yylocp, yystack]b4_user_args[); } #if YYDEBUG @@ -1331,7 +1376,7 @@ m4_define_default([b4_header_guard], static void yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, - yyGLRStack* yystack) + yyGLRStack* yystack]b4_pure_formals[) { /* `Unused' warnings. */ (void) yyx0; @@ -1345,7 +1390,7 @@ m4_define_default([b4_header_guard], yyreportTree (yyx1, 2); YYFPRINTF (stderr, "\n"); #endif - yyFail (yystack, "ambiguity detected"); + ]b4_yyFail(yystack, "ambiguity detected")[; } @@ -1353,7 +1398,7 @@ m4_define_default([b4_header_guard], * actions, and return the result. */ static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack, - YYSTYPE* yyvalp, YYLTYPE* yylocp YY_USER_FORMALS) + YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) { yySemanticOption* yybest; yySemanticOption* yyp; @@ -1369,7 +1414,7 @@ m4_define_default([b4_header_guard], switch (yypreference (yybest, yyp)) { case 0: - yyreportAmbiguity (yybest, yyp, yystack); + yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[); break; case 1: yymerge = 1; @@ -1386,25 +1431,25 @@ m4_define_default([b4_header_guard], if (yymerge) { int yyprec = yydprec[yybest->yyrule]; - YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp YY_USER_ARGS)); + YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[)); for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext) { if (yyprec == yydprec[yyp->yyrule]) { YYSTYPE yyval1; YYLTYPE yydummy; - YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy YY_USER_ARGS)); + YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[)); *yyvalp = yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1); } } return yyok; } else - return yyresolveAction (yybest, yystack, yyvalp, yylocp YY_USER_ARGS); + return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[); } static YYRESULTTAG -yyresolveStack (yyGLRStack* yystack YY_USER_FORMALS) +yyresolveStack (yyGLRStack* yystack]b4_user_formals[) { if (yystack->yysplitPoint != NULL) { @@ -1416,7 +1461,7 @@ m4_define_default([b4_header_guard], yys = yys->yypred, yyn += 1) ; YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack - YY_USER_ARGS)); + ]b4_user_args[)); } return yyok; } @@ -1454,7 +1499,7 @@ m4_define_default([b4_header_guard], static YYRESULTTAG yyprocessOneStack (yyGLRStack* yystack, int yyk, size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp - YY_USER_FORMALS) + ]b4_user_formals[) { int yyaction; const short* yyconflicts; @@ -1475,7 +1520,7 @@ m4_define_default([b4_header_guard], yymarkStackDeleted (yystack, yyk); return yyok; } - YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse YY_USER_ARGS)); + YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_lpure_args[)); } else { @@ -1495,9 +1540,9 @@ m4_define_default([b4_header_guard], YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n", yynewStack, yyk)); YYCHK (yyglrReduce (yystack, yynewStack, - *yyconflicts, yyfalse YY_USER_ARGS)); + *yyconflicts, yyfalse]b4_lpure_args[)); YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn, - yylvalp, yyllocp YY_USER_ARGS)); + yylvalp, yyllocp]b4_user_args[)); yyconflicts += 1; } @@ -1505,7 +1550,8 @@ m4_define_default([b4_header_guard], { YYDPRINTF ((stderr, "Shifting token %s on stack %d, ", yytokenName (*yytokenp), yyk)); - yyglrShift (yystack, yyk, yyaction, yyposn+1, *yylvalp, yyllocp); + yyglrShift (yystack, yyk, yyaction, yyposn+1, + *yylvalp, yyllocp]b4_user_args[); YYDPRINTF ((stderr, "which is now in state #%d\n", yystack->yytops.yystates[yyk]->yylrState)); break; @@ -1517,14 +1563,15 @@ m4_define_default([b4_header_guard], break; } else - YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse YY_USER_ARGS)); + YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_lpure_args[)); } } return yyok; } static void -yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) +yyreportParseError (yyGLRStack* yystack, + YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) { /* `Unused' warnings. */ (void) yylvalp; @@ -1568,12 +1615,12 @@ m4_define_default([b4_header_guard], yyprefix = " or "; } } - yyerror (yymsg); + yyerror (yymsg]b4_lpure_args[); free (yymsg); } else #endif - yyerror ("parse error"); + yyerror ("parse error"]b4_lpure_args[); yynerrs += 1; } } @@ -1582,7 +1629,8 @@ m4_define_default([b4_header_guard], YYLVALP, and YYLLOCP point to the syntactic category, semantic value, and location of the lookahead. */ static void -yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) +yyrecoverParseError (yyGLRStack* yystack, + YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) { yySymbol* const yytokenp = yystack->yytokenp; size_t yyk; @@ -1596,7 +1644,7 @@ m4_define_default([b4_header_guard], while (yytrue) { if (*yytokenp == YYEOF) - yyFail (yystack, NULL); + yyCut (yystack); if (*yytokenp != YYEMPTY) YYDPRINTF ((stderr, "Discarding token %s\n", yytokenName (*yytokenp))); @@ -1607,7 +1655,7 @@ m4_define_default([b4_header_guard], yyj = yypact[yystack->yytops.yystates[0]->yylrState]; if (yyj == YYPACT_NINF) /* Something's not right; we shouldn't be here. */ - yyFail (yystack, NULL); + yyCut (yystack); yyj += *yytokenp; if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp) { @@ -1623,7 +1671,7 @@ m4_define_default([b4_header_guard], if (yystack->yytops.yystates[yyk] != NULL) break; if (yyk >= yystack->yytops.yysize) - yyFail (yystack, NULL); + yyCut (yystack); for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1) yymarkStackDeleted (yystack, yyk); yyremoveDeletes (yystack); @@ -1637,7 +1685,8 @@ m4_define_default([b4_header_guard], yycheck[yyj] == YYTERROR && yyisShiftAction (yytable[yyj])) { yyglrShift (yystack, 0, yytable[yyj], - yystack->yytops.yystates[0]->yyposn, *yylvalp, yyllocp); + yystack->yytops.yystates[0]->yyposn, + *yylvalp, yyllocp]b4_user_args[); break; } yystack->yytops.yystates[0] = yystack->yytops.yystates[0]->yypred; @@ -1645,7 +1694,7 @@ m4_define_default([b4_header_guard], yystack->yyspaceLeft += 1; } if (yystack->yytops.yystates[0] == NULL) - yyFail (yystack, NULL); + yyCut (yystack); } #define YYCHK1(YYE) \ @@ -1693,7 +1742,7 @@ m4_define_default([b4_header_guard], if (setjmp (yystack.yyexception_buffer) != 0) goto yyDone; - yyglrShift (&yystack, 0, 0, 0, yyval_default, &yyloc_default); + yyglrShift (&yystack, 0, 0, 0, yyval_default, &yyloc_default]b4_user_args[); yytoken = YYEMPTY; yyposn = 0; @@ -1718,10 +1767,10 @@ m4_define_default([b4_header_guard], yyrule = yydefaultAction (yystate); if (yyrule == 0) { - yyreportParseError (&yystack, yylvalp, yyllocp); + yyreportParseError (&yystack, yylvalp, yyllocp]b4_user_args[); goto yyuser_error; } - YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue YY_USER_ARGS)); + YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_lpure_args[)); } else { @@ -1743,7 +1792,8 @@ m4_define_default([b4_header_guard], if (yytoken != YYEOF) yytoken = YYEMPTY; yyposn += 1; - yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp); + yyglrShift (&yystack, 0, yyaction, yyposn, + yylval, yyllocp]b4_user_args[); if (0 < yystack.yyerrState) yystack.yyerrState -= 1; YYDPRINTF ((stderr, "Entering state %d\n", @@ -1751,11 +1801,11 @@ m4_define_default([b4_header_guard], } else if (yyisErrorAction (yyaction)) { - yyreportParseError (&yystack, yylvalp, yyllocp); + yyreportParseError (&yystack, yylvalp, yyllocp]b4_user_args[); goto yyuser_error; } else - YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue YY_USER_ARGS)); + YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_lpure_args[)); } } @@ -1765,7 +1815,7 @@ m4_define_default([b4_header_guard], int yyn = yystack.yytops.yysize; for (yys = 0; yys < yyn; yys += 1) YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn, - yylvalp, yyllocp YY_USER_ARGS)); + yylvalp, yyllocp]b4_user_args[)); yytoken = YYEMPTY; yyposn += 1; yyremoveDeletes (&yystack); @@ -1773,15 +1823,15 @@ m4_define_default([b4_header_guard], { yyundeleteLastStack (&yystack); if (yystack.yytops.yysize == 0) - yyFail (&yystack, "parse error"); - YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS)); + yyFail (&yystack][]b4_lpure_args[, "parse error"); + YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); - yyreportParseError (&yystack, yylvalp, yyllocp); + yyreportParseError (&yystack, yylvalp, yyllocp]b4_user_args[); goto yyuser_error; } else if (yystack.yytops.yysize == 1) { - YYCHK1 (yyresolveStack (&yystack YY_USER_ARGS)); + YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); yycompressStack (&yystack); break; @@ -1789,7 +1839,7 @@ m4_define_default([b4_header_guard], } continue; yyuser_error: - yyrecoverParseError (&yystack, yylvalp, yyllocp); + yyrecoverParseError (&yystack, yylvalp, yyllocp]b4_user_args[); yyposn = yystack.yytops.yystates[0]->yyposn; } yyDone: Index: tests/calc.at --- tests/calc.at Sun, 27 Oct 2002 13:07:36 +0100 akim +++ tests/calc.at Sat, 02 Nov 2002 17:53:35 +0100 akim @@ -81,16 +81,20 @@ m4_define([_AT_DATA_CALC_Y], # define VAL (yylval) #endif +#if YYLSP_NEEDED +# define YYLLOC_FORMAL , YYLTYPE *yylloc +# define YYLLOC_ARG , yylloc +# define USE_YYLLOC (void) yylloc; +#else +# define YYLLOC_FORMAL +# define YYLLOC_ARG +# define USE_YYLLOC +#endif + #if YYPURE -# if YYLSP_NEEDED -# define LEX_FORMALS YYSTYPE *yylval, YYLTYPE *yylloc -# define LEX_ARGS yylval, yylloc -# define USE_LEX_ARGS (void) yylval; (void) yylloc; -# else -# define LEX_FORMALS YYSTYPE *yylval -# define LEX_ARGS yylval -# define USE_LEX_ARGS (void) yylval -# endif +# define LEX_FORMALS YYSTYPE *yylval YYLLOC_FORMAL +# define LEX_ARGS yylval YYLLOC_ARG +# define USE_LEX_ARGS (void) yylval; USE_YYLLOC # define LEX_PRE_FORMALS LEX_FORMALS, # define LEX_PRE_ARGS LEX_ARGS, #else @@ -102,7 +106,12 @@ m4_define([_AT_DATA_CALC_Y], #endif static int power (int base, int exponent); -static void yyerror (const char *s); +static void yyerror (const char *s +#if YYPURE + YYLLOC_FORMAL +#endif + , value_t *result, int *count + ); static int yylex (LEX_FORMALS); static int yygetc (LEX_FORMALS); static void yyungetc (LEX_PRE_FORMALS int c); @@ -155,7 +164,12 @@ exp: FILE *yyin; static void -yyerror (const char *s) +yyerror (const char *s +#if YYPURE + YYLLOC_FORMAL +#endif + , value_t *result, int *count + ) { #if YYLSP_NEEDED fprintf (stderr, "%d.%d-%d.%d: ", @@ -323,8 +337,7 @@ exp: # ------------------------------- # Produce `calc.y'. m4_define([AT_DATA_CALC_Y], -[_AT_DATA_CALC_Y($[1], $[2], $[3], - [m4_bpatsubst([$1], [--[^ ]*])]) +[_AT_DATA_CALC_Y($[1], $[2], $[3], [$1]) ]) @@ -360,7 +373,7 @@ m4_define([_AT_CHECK_CALC], # If INPUT starts with a slash, it is used as absolute input file name, # otherwise as contents. # -# If BISON-OPTIONS contains `--location', then make sure the ERROR-LOCATION +# If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION # is correctly output on stderr. # # If BISON-OPTIONS contains `%error-verbose', then make sure the @@ -426,7 +439,7 @@ m4_define([AT_CHECK_CALC], AT_DATA_CALC_Y([$1]) # Specify the output files to avoid problems on different file systems. -AT_CHECK([bison -o calc.c m4_bpatsubst([$1], [%[^ ]*]) calc.y], +AT_CHECK([bison -o calc.c calc.y], [0], [], []) AT_COMPILE([calc]) @@ -495,22 +508,21 @@ m4_define([AT_CHECK_CALC_LALR], AT_CHECK_CALC_LALR() -AT_CHECK_CALC_LALR([--defines]) +AT_CHECK_CALC_LALR([%defines]) AT_CHECK_CALC_LALR([%locations]) -AT_CHECK_CALC_LALR([--name-prefix=calc]) -AT_CHECK_CALC_LALR([--verbose]) -AT_CHECK_CALC_LALR([--yacc]) +AT_CHECK_CALC_LALR([%name-prefix="calc"]) +AT_CHECK_CALC_LALR([%verbose]) +AT_CHECK_CALC_LALR([%yacc]) AT_CHECK_CALC_LALR([%error-verbose]) AT_CHECK_CALC_LALR([%error-verbose %locations]) -AT_CHECK_CALC_LALR([%error-verbose %locations --defines --name-prefix=calc --verbose --yacc]) +AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) AT_CHECK_CALC_LALR([%debug]) -AT_CHECK_CALC_LALR([%error-verbose %debug %locations --defines --name-prefix=calc --verbose --yacc]) +AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) -# FIXME: Not ready yet. -# AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations --defines --name-prefix=calc --verbose --yacc]) +AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) # ----------------------- # @@ -529,18 +541,18 @@ m4_define([AT_CHECK_CALC_GLR], AT_CHECK_CALC_GLR() -AT_CHECK_CALC_GLR([--defines]) +AT_CHECK_CALC_GLR([%defines]) AT_CHECK_CALC_GLR([%locations]) -AT_CHECK_CALC_GLR([--name-prefix=calc]) -AT_CHECK_CALC_GLR([--verbose]) -AT_CHECK_CALC_GLR([--yacc]) +AT_CHECK_CALC_GLR([%name-prefix="calc"]) +AT_CHECK_CALC_GLR([%verbose]) +AT_CHECK_CALC_GLR([%yacc]) AT_CHECK_CALC_GLR([%error-verbose]) AT_CHECK_CALC_GLR([%error-verbose %locations]) -AT_CHECK_CALC_GLR([%error-verbose %locations --defines --name-prefix=calc --verbose --yacc]) +AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) AT_CHECK_CALC_GLR([%debug]) -AT_CHECK_CALC_GLR([%error-verbose %debug %locations --defines --name-prefix=calc --verbose --yacc]) +AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) -# AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations --defines --name-prefix=calc --verbose --yacc]) +AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) Index: tests/cxx-type.at --- tests/cxx-type.at Sun, 27 Oct 2002 13:07:36 +0100 akim +++ tests/cxx-type.at Sat, 02 Nov 2002 18:06:14 +0100 akim @@ -36,7 +36,11 @@ m4_define([_AT_TEST_GLR_CALC], ]m4_bmatch([$2], [stmtMerge], [ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[ #define YYINITDEPTH 10 - int yyerror (const char *s); + int yyerror (const char *s +#if YYPURE && YYLSP_NEEDED + , YYLTYPE *yylocation +#endif + ); #if YYPURE ]m4_bmatch([$1], [location], @@ -130,7 +134,7 @@ m4_define([_AT_TEST_GLR_CALC], break; default: if (isalpha (c)) - { + { i = 0; do @@ -153,8 +157,15 @@ m4_define([_AT_TEST_GLR_CALC], } int -yyerror (const char *s) +yyerror (const char *s +#if YYPURE && YYLSP_NEEDED + , YYLTYPE *yylocation +#endif + ) { +#if YYPURE && YYLSP_NEEDED + (void) *yylocation; +#endif fprintf (stderr, "%s\n", s); return 0; } @@ -241,62 +252,56 @@ m4_define([_AT_VERBOSE_GLR_STDERR], AT_SETUP([GLR: Resolve ambiguity, impure, no locations]) _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2]) -AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, impure, locations]) _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2]) -AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, pure, no locations]) _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2]) -AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) +AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, pure, locations]) _AT_TEST_GLR_CALC([%pure-parser %locations],[%dprec 1],[%dprec 2]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_RESOLVED_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, no locations]) _AT_TEST_GLR_CALC([],[%merge ],[%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, locations]) _AT_TEST_GLR_CALC([%locations],[%merge ],[%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, no locations]) _AT_TEST_GLR_CALC([%pure-parser],[%merge ],[%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, locations]) _AT_TEST_GLR_CALC([%pure-parser %locations],[%merge ],[%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations]) _AT_TEST_GLR_CALC([%error-verbose], [%merge ],[%merge ]) AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, - _AT_AMBIG_GLR_OUTPUT, - _AT_VERBOSE_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR) AT_CLEANUP