X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/55f48c48314bf63e224f5cbfad7f9c52b6d78df7..9d3f7eaf1deedb6518857d24d4bfa0e51534ecf9:/tests/glr-regression.at diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 9c534631..8570b19d 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,8 +81,7 @@ yylex (void) for (;;) { int ch; - if (feof (stdin)) - abort (); + assert (!feof (stdin)); ch = getchar (); if (ch == EOF) return 0; @@ -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]) @@ -384,7 +383,7 @@ B: 'a' { $$ = make_value ("B", "'a'"); } ; %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([a])[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) @@ -467,7 +466,7 @@ start: ; %% -]AT_YYLEX_DEFINE(a)[ +]AT_YYLEX_DEFINE(["a"])[ ]AT_YYERROR_DEFINE[ int main (void) @@ -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) { @@ -657,7 +646,6 @@ AT_DATA_GRAMMAR([glr-regr8.y], #include ]AT_YYERROR_DECLARE[ ]AT_YYLEX_DECLARE[ - ]AT_YYERROR_DECLARE[ %} %token T_CONSTANT @@ -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) @@ -909,7 +889,7 @@ start: %% ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE([a])[ +]AT_YYLEX_DEFINE(["a"])[ int main (void) @@ -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) @@ -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) @@ -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 *); @@ -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'; @@ -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) @@ -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) @@ -1578,7 +1527,8 @@ AT_CLEANUP 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,17 +1539,10 @@ 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 { - @$.first_line = 1; - @$.first_column = 1; - @$.last_line = 1; - @$.last_column = 1; -} - %% /* Tests the case of an empty RHS that has inherited the location of the @@ -1620,21 +1563,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 +1593,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 +1612,7 @@ AT_DATA_GRAMMAR([glr-regr18.y], %{ #include ]AT_YYERROR_DECLARE[ - static int yylex (); + ]AT_YYLEX_DECLARE[ %} %union { @@ -1695,9 +1632,8 @@ sym3: %merge { $$ = 0; } ; %type sym3; %% - ]AT_YYERROR_DEFINE[ -]AT_YYLEX_DEFINE()[ +]AT_YYLEX_DEFINE[ int main (void) { @@ -1743,7 +1679,7 @@ start: b: 'b'; d: /* nada. */; %% -]AT_YYLEX_DEFINE([abc])[ +]AT_YYLEX_DEFINE(["abc"])[ ]AT_YYERROR_DEFINE[ int main (void)