X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/e436fa677c748f52929996590d3e46b5f984d6dc..84271837f686cc9bdf2d7483d4493f26b52d133d:/tests/glr-regression.at?ds=sidebyside diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 67c60707..07c9fe25 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -32,11 +32,12 @@ AT_DATA_GRAMMAR([glr-regr1.y], %{ #include #include +#include #define YYSTYPE int static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1); -]AT_YYLEX_DECLARE[ ]AT_YYERROR_DECLARE[ +]AT_YYLEX_DECLARE[ %} @@ -80,13 +81,12 @@ yylex (void) for (;;) { int ch; - if (feof (stdin)) - abort (); + assert (!feof (stdin)); ch = getchar (); if (ch == EOF) - return 0; + return 0; else if (ch == 'B' || ch == 'P') - return ch; + return ch; } } ]]) @@ -128,8 +128,9 @@ AT_DATA_GRAMMAR([glr-regr2a.y], #include #include #include - ]AT_YYLEX_DECLARE[ + #include ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ %} %glr-parser @@ -177,8 +178,7 @@ yylex (void) { char buf[50]; char *s; - if (feof (stdin)) - abort (); + assert (!feof (stdin)); switch (fscanf (input, " %1[a-z,]", buf)) { case 1: @@ -190,8 +190,7 @@ yylex (void) } if (fscanf (input, "%49s", buf) != 1) return 0; - if (sizeof buf - 1 <= strlen (buf)) - abort (); + assert (strlen (buf) < sizeof buf - 1); s = (char *) malloc (strlen (buf) + 1); strcpy (s, buf); yylval = s; @@ -242,6 +241,7 @@ AT_DATA_GRAMMAR([glr-regr3.y], #include #include #include +#include static int MergeRule (int x0, int x1); ]AT_YYERROR_DECLARE[ @@ -302,8 +302,7 @@ int T[] = { T1, T2, T3, T4 }; int yylex (void) { char inp[3]; - if (feof (stdin)) - abort (); + assert (!feof (stdin)); if (fscanf (input, "%2s", inp) == EOF) return 0; switch (inp[0]) @@ -339,7 +338,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Duplicate representation of merged trees. See ## +## Duplicate representation of merged trees. See ## ## . ## ## ------------------------------------------------------------------------- ## @@ -384,7 +383,7 @@ B: 'a' { $$ = make_value ("B", "'a'"); } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([a])[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) @@ -430,7 +429,7 @@ AT_CLEANUP ## -------------------------------------------------------------------------- ## -## User destructor for unresolved GLR semantic value. See ## +## User destructor for unresolved GLR semantic value. See ## ## . ## ## -------------------------------------------------------------------------- ## @@ -467,7 +466,7 @@ start: ; %% -]AT_YYLEX_DEFINE(a)[ +]AT_YYLEX_DEFINE(["a"])[ ]AT_YYERROR_DEFINE[ int main (void) @@ -490,7 +489,7 @@ AT_CLEANUP ## -------------------------------------------------------------------------- ## -## User destructor after an error during a split parse. See ## +## User destructor after an error during a split parse. See ## ## . ## ## -------------------------------------------------------------------------- ## @@ -519,18 +518,8 @@ AT_DATA_GRAMMAR([glr-regr6.y], start: 'a' | 'a' ; %% - -static int -yylex (void) -{ - static char const input[] = "a"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - return input[toknum++]; -} - ]AT_YYERROR_DEFINE[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) { @@ -554,7 +543,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Duplicated user destructor for lookahead. See ## +## Duplicated user destructor for lookahead. See ## ## . ## ## ------------------------------------------------------------------------- ## @@ -642,7 +631,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## ## Incorrect default location for empty right-hand sides. Adapted from bug ## -## report by Claudia Hermann. ## +## report by Claudia Hermann. ## ## See http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00069.html and ## ## http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00072.html ## ## ------------------------------------------------------------------------- ## @@ -657,7 +646,6 @@ AT_DATA_GRAMMAR([glr-regr8.y], #include ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ - ]AT_YYERROR_DECLARE[ %} %token T_CONSTANT @@ -669,25 +657,25 @@ AT_DATA_GRAMMAR([glr-regr8.y], %% -PortClause : T_PORT InterfaceDeclaration T_PORT - { printf("%d/%d - %d/%d - %d/%d\n", - @1.first_column, @1.last_column, - @2.first_column, @2.last_column, - @3.first_column, @3.last_column); } - ; +PortClause : T_PORT InterfaceDeclaration T_PORT + { printf("%d/%d - %d/%d - %d/%d\n", + @1.first_column, @1.last_column, + @2.first_column, @2.last_column, + @3.first_column, @3.last_column); } + ; -InterfaceDeclaration : OptConstantWord %dprec 1 - | OptSignalWord %dprec 2 - ; +InterfaceDeclaration : OptConstantWord %dprec 1 + | OptSignalWord %dprec 2 + ; -OptConstantWord : /* empty */ - | T_CONSTANT - ; +OptConstantWord : /* empty */ + | T_CONSTANT + ; -OptSignalWord : /* empty */ - { printf("empty: %d/%d\n", @$.first_column, @$.last_column); } - | T_SIGNAL - ; +OptSignalWord : /* empty */ + { printf("empty: %d/%d\n", @$.first_column, @$.last_column); } + | T_SIGNAL + ; %% @@ -738,7 +726,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## No users destructors if stack 0 deleted. See ## +## No users destructors if stack 0 deleted. See ## ## . ## ## ------------------------------------------------------------------------- ## @@ -816,7 +804,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Corrupted semantic options if user action cuts parse. ## +## Corrupted semantic options if user action cuts parse. ## ## ------------------------------------------------------------------------- ## AT_SETUP([Corrupted semantic options if user action cuts parse]) @@ -845,16 +833,8 @@ start: ; %% - ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static int called; - if (called++) - abort (); - return 0; -} +]AT_YYLEX_DEFINE[ int main (void) @@ -878,7 +858,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Undesirable destructors if user action cuts parse. ## +## Undesirable destructors if user action cuts parse. ## ## ------------------------------------------------------------------------- ## AT_SETUP([Undesirable destructors if user action cuts parse]) @@ -909,7 +889,7 @@ start: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([a])[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) @@ -936,7 +916,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Leaked semantic values if user action cuts parse. ## +## Leaked semantic values if user action cuts parse. ## ## ------------------------------------------------------------------------- ## AT_SETUP([Leaked semantic values if user action cuts parse]) @@ -954,6 +934,7 @@ AT_DATA_GRAMMAR([glr-regr12.y], %{ # include +# include static int merge (YYSTYPE, YYSTYPE); ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ @@ -1017,17 +998,9 @@ merge (YYSTYPE s1, YYSTYPE s2) } ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static int const input[] = { PARENT_RHS_AFTER, 0 }; - static size_t toknum; - if (! (toknum < sizeof input / sizeof *input)) - abort (); - if (input[toknum] == PARENT_RHS_AFTER) - parent_rhs_after_value = 1; - return input[toknum++]; -} +]AT_YYLEX_DEFINE([{ PARENT_RHS_AFTER, 0 }], + [if (res == PARENT_RHS_AFTER) + parent_rhs_after_value = 1;])[ int main (void) @@ -1064,7 +1037,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Incorrect lookahead during deterministic GLR. See ## +## Incorrect lookahead during deterministic GLR. See ## ## and ## ## . ## ## ------------------------------------------------------------------------- ## @@ -1083,6 +1056,7 @@ AT_DATA_GRAMMAR([glr-regr13.y], %{ #include + #include ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ static void print_lookahead (char const *); @@ -1136,18 +1110,8 @@ change_lookahead: %% ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static char const input[] = "ab"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = toknum + 1; - yylval.value = input[toknum] + 'A' - 'a'; - return input[toknum++]; -} +]AT_YYLEX_DEFINE(["ab"], + [yylval.value = res + 'A' - 'a'])[ static void print_lookahead (char const *reduction) @@ -1161,10 +1125,10 @@ print_lookahead (char const *reduction) { printf ("'%c', yylval='", yychar); if (yylval.value > ' ') - printf ("%c", yylval.value); + printf ("%c", yylval.value); printf ("', yylloc=(%d,%d),(%d,%d)", - yylloc.first_line, yylloc.first_column, - yylloc.last_line, yylloc.last_column); + yylloc.first_line, yylloc.first_column, + yylloc.last_line, yylloc.last_column); } printf ("\n"); } @@ -1199,7 +1163,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Incorrect lookahead during nondeterministic GLR. ## +## Incorrect lookahead during nondeterministic GLR. ## ## ------------------------------------------------------------------------- ## AT_SETUP([Incorrect lookahead during nondeterministic GLR]) @@ -1231,6 +1195,7 @@ AT_DATA_GRAMMAR([glr-regr14.y], %{ #include #include + #include ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ static void print_lookahead (char const *); @@ -1260,7 +1225,7 @@ merge: | conflict defstate_look 'a' nonconflict2 'b' defstate_shift %dprec 2 { USE ($3); USE ($5); print_lookahead ("merge <- conflict defstate_look 'a' nonconflict2 'b'" - " defstate_shift"); + " defstate_shift"); } ; @@ -1307,7 +1272,7 @@ alt1: USE ($1); if (yychar != 'd' && yychar != YYEOF) { - fprintf (stderr, "Incorrect lookahead during stack explosion.\n"); + fprintf (stderr, "Incorrect lookahead during stack explosion.\n"); } } ; @@ -1316,7 +1281,7 @@ alt2: USE ($1); if (yychar != 'd' && yychar != YYEOF) { - fprintf (stderr, "Incorrect lookahead during stack explosion.\n"); + fprintf (stderr, "Incorrect lookahead during stack explosion.\n"); } } ; @@ -1325,7 +1290,7 @@ alt3: USE ($1); if (yychar != 'd' && yychar != YYEOF) { - fprintf (stderr, "Incorrect lookahead during stack explosion.\n"); + fprintf (stderr, "Incorrect lookahead during stack explosion.\n"); } } ; @@ -1333,8 +1298,8 @@ no_look: { if (yychar != YYEMPTY) { - fprintf (stderr, - "Found lookahead where shouldn't during stack explosion.\n"); + fprintf (stderr, + "Found lookahead where shouldn't during stack explosion.\n"); } } ; @@ -1347,8 +1312,7 @@ yylex (void) { static char const input[] = "abcdddd"; static size_t toknum; - if (! (toknum < sizeof input)) - abort (); + assert (toknum < sizeof input); yylloc.first_line = yylloc.last_line = 1; yylloc.first_column = yylloc.last_column = toknum + 1; yylval.value = input[toknum] + 'A' - 'a'; @@ -1367,10 +1331,10 @@ print_lookahead (char const *reduction) { printf ("'%c', yylval='", yychar); if (yylval.value > ' ') - printf ("%c", yylval.value); + printf ("%c", yylval.value); printf ("', yylloc=(%d,%d),(%d,%d)", - yylloc.first_line, yylloc.first_column, - yylloc.last_line, yylloc.last_column); + yylloc.first_line, yylloc.first_column, + yylloc.last_line, yylloc.last_column); } printf ("\n"); } @@ -1416,7 +1380,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Leaked semantic values when reporting ambiguity. ## +## Leaked semantic values when reporting ambiguity. ## ## ------------------------------------------------------------------------- ## AT_SETUP([Leaked semantic values when reporting ambiguity]) @@ -1468,16 +1432,8 @@ ambiguity1: ; ambiguity2: ; %% - ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static int called; - if (called++) - abort (); - return 0; -} +]AT_YYLEX_DEFINE[ int main (void) @@ -1506,7 +1462,7 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Leaked lookahead after nondeterministic parse syntax error. ## +## Leaked lookahead after nondeterministic parse syntax error. ## ## ------------------------------------------------------------------------- ## AT_SETUP([Leaked lookahead after nondeterministic parse syntax error]) @@ -1519,6 +1475,7 @@ AT_DATA_GRAMMAR([glr-regr16.y], %{ # include +# include ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ static int lookahead_value = 0; @@ -1534,17 +1491,9 @@ alt2: ; %% ]AT_YYERROR_DEFINE[ -static int -yylex (void) -{ - static char const input[] = "ab"; - static size_t toknum; - if (! (toknum < sizeof input)) - abort (); - if (input[toknum] == 'b') - lookahead_value = 1; - return input[toknum++]; -} +]AT_YYLEX_DEFINE(["ab"], + [if (res == 'b') + lookahead_value = 1])[ int main (void) @@ -1573,12 +1522,13 @@ AT_CLEANUP ## ------------------------------------------------------------------------- ## -## Uninitialized location when reporting ambiguity. ## +## Uninitialized location when reporting ambiguity. ## ## ------------------------------------------------------------------------- ## AT_SETUP([Uninitialized location when reporting ambiguity]) -AT_BISON_OPTION_PUSHDEFS +AT_BISON_OPTION_PUSHDEFS([%glr-parser %locations %define api.pure]) + AT_DATA_GRAMMAR([glr-regr17.y], [[ %glr-parser @@ -1589,8 +1539,8 @@ AT_DATA_GRAMMAR([glr-regr17.y], %union { int dummy; } %{ - static void yyerror (YYLTYPE *, char const *); - static int yylex (YYSTYPE *, YYLTYPE *); + ]AT_YYERROR_DECLARE[ + ]AT_YYLEX_DECLARE[ %} %initial-action { @@ -1620,21 +1570,15 @@ empty1: ; empty2: ; %% +# include -static void -yyerror (YYLTYPE *locp, char const *msg) -{ - fprintf (stderr, "%d.%d-%d.%d: %s.\n", locp->first_line, - locp->first_column, locp->last_line, locp->last_column, msg); -} - +]AT_YYERROR_DEFINE[ static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp) { static char const input[] = "ab"; static size_t toknum; - if (! (toknum < sizeof input)) - abort (); + assert (toknum < sizeof input); lvalp->dummy = 0; llocp->first_line = llocp->last_line = 2; llocp->first_column = toknum + 1; @@ -1656,7 +1600,7 @@ AT_BISON_CHECK([[-o glr-regr17.c glr-regr17.y]], 0, [], AT_COMPILE([glr-regr17]) AT_PARSER_CHECK([[./glr-regr17]], 0, [], -[1.1-2.3: syntax is ambiguous. +[1.1-2.2: syntax is ambiguous ]) AT_CLEANUP @@ -1675,7 +1619,7 @@ AT_DATA_GRAMMAR([glr-regr18.y], %{ #include ]AT_YYERROR_DECLARE[ - static int yylex (); + ]AT_YYLEX_DECLARE[ %} %union { @@ -1695,9 +1639,8 @@ sym3: %merge { $$ = 0; } ; %type sym3; %% - ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE()[ +]AT_YYLEX_DEFINE[ int main (void) { @@ -1743,7 +1686,7 @@ start: b: 'b'; d: /* nada. */; %% -]AT_YYLEX_DEFINE([abc])[ +]AT_YYLEX_DEFINE(["abc"])[ ]AT_YYERROR_DEFINE[ int main (void)