# Checking GLR Parsing: Regression Tests -*- Autotest -*-
-# Copyright (C) 2002-2003, 2005-2007, 2009-2012 Free Software
+# Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software
# Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
AT_BANNER([[GLR Regression Tests]])
-## --------------------------- ##
-## Badly Collapsed GLR States. ##
-## --------------------------- ##
+## ---------------------------- ##
+## Badly Collapsed GLR States. ##
+## ---------------------------- ##
AT_SETUP([Badly Collapsed GLR States])
%{
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
-]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
return 0;
}
+const char *input = YY_NULL;
+
int
-main (void)
+main (int argc, const char* argv[])
{
+ assert (argc == 2);
+ input = argv[1];
return yyparse ();
}
int
yylex (void)
{
- for (;;)
- {
- int ch;
- if (feof (stdin))
- abort ();
- ch = getchar ();
- if (ch == EOF)
- return 0;
- else if (ch == 'B' || ch == 'P')
- return ch;
- }
+ return *input++;
}
]])
AT_BISON_OPTION_POPDEFS
[glr-regr1.y: conflicts: 1 shift/reduce
])
AT_COMPILE([glr-regr1])
-AT_PARSER_CHECK([[echo BPBPB | ./glr-regr1]], 0,
+AT_PARSER_CHECK([[./glr-regr1 BPBPB]], 0,
[[E -> 'B'
E -> 'B'
E -> E 'P' E
AT_CLEANUP
-## ------------------------------------------------------------ ##
-## Improper handling of embedded actions and $-N in GLR parsers ##
-## ------------------------------------------------------------ ##
+## -------------------------------------------------------------- ##
+## Improper handling of embedded actions and $-N in GLR parsers. ##
+## -------------------------------------------------------------- ##
AT_SETUP([Improper handling of embedded actions and dollar(-N) in GLR parsers])
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
- ]AT_YYLEX_DECLARE[
+ #include <assert.h>
]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
%}
%glr-parser
{
char buf[50];
char *s;
- if (feof (stdin))
- abort ();
+ assert (!feof (stdin));
switch (fscanf (input, " %1[a-z,]", buf))
{
case 1:
}
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;
int
main (int argc, char **argv)
{
+ int res;
input = stdin;
- if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
- return yyparse ();
+ if (argc == 2 && !(input = fopen (argv[1], "r")))
+ return 3;
+ res = yyparse ();
+ if (argc == 2 && fclose (input))
+ return 4;
+ return res;
}
]])
AT_BISON_OPTION_POPDEFS
])
AT_COMPILE([glr-regr2a])
-AT_PARSER_CHECK([[echo s VARIABLE_1 t v x q | ./glr-regr2a]], 0,
+AT_DATA([input1.txt],
+[[s VARIABLE_1 t v x q
+]])
+AT_PARSER_CHECK([[./glr-regr2a input1.txt]], 0,
[[Variable: 'VARIABLE_1'
-]], [])
-AT_PARSER_CHECK([[echo s VARIABLE_1 , ANOTHER_VARIABLE_2 t e | ./glr-regr2a]],
+]])
+
+AT_DATA([input2.txt],
+[[s VARIABLE_1 , ANOTHER_VARIABLE_2 t e
+]])
+AT_PARSER_CHECK([[./glr-regr2a input2.txt]],
0,
[[Varlist: 'VARIABLE_1,ANOTHER_VARIABLE_2'
]])
-AT_PARSER_CHECK([[echo s VARIABLE_3 t v x | ./glr-regr2a]], 0,
+
+AT_DATA([input3.txt],
+[[s VARIABLE_3 t v x
+]])
+AT_PARSER_CHECK([[./glr-regr2a input3.txt]], 0,
[[Variable: 'VARIABLE_3'
-]], [])
+]])
AT_CLEANUP
-## ------------------------------------------------------------ ##
-## Improper merging of GLR delayed action sets ##
-## ------------------------------------------------------------ ##
+## --------------------------------------------- ##
+## Improper merging of GLR delayed action sets. ##
+## --------------------------------------------- ##
AT_SETUP([Improper merging of GLR delayed action sets])
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <assert.h>
static int MergeRule (int x0, int x1);
]AT_YYERROR_DECLARE[
int yylex (void)
{
char inp[3];
- if (feof (stdin))
- abort ();
+ assert (!feof (stdin));
if (fscanf (input, "%2s", inp) == EOF)
return 0;
switch (inp[0])
int
main(int argc, char* argv[])
{
+ int res;
input = stdin;
- if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
- return yyparse ();
+ if (argc == 2 && !(input = fopen (argv[1], "r")))
+ return 3;
+ res = yyparse ();
+ if (argc == 2 && fclose (input))
+ return 4;
+ return res;
}
]])
AT_BISON_OPTION_POPDEFS
])
AT_COMPILE([glr-regr3])
-AT_PARSER_CHECK([[echo p1 t4 o2 p1 p1 t1 o1 t2 p2 o1 t3 p2 p2 | ./glr-regr3]],
+AT_DATA([input.txt],
+[[p1 t4 o2 p1 p1 t1 o1 t2 p2 o1 t3 p2 p2
+]])
+AT_PARSER_CHECK([[./glr-regr3 input.txt]],
0,
[[Result: 1c04
-]], [])
+]])
AT_CLEANUP
-## ------------------------------------------------------------------------- ##
-## Duplicate representation of merged trees. See ##
-## <http://lists.gnu.org/archive/html/help-bison/2005-07/msg00013.html>. ##
-## ------------------------------------------------------------------------- ##
+## ---------------------------------------------------------------------- ##
+## Duplicate representation of merged trees. See ##
+## <http://lists.gnu.org/archive/html/help-bison/2005-07/msg00013.html>. ##
+## ---------------------------------------------------------------------- ##
AT_SETUP([Duplicate representation of merged trees])
%%
]AT_YYERROR_DEFINE[
-]AT_YYLEX_DEFINE([a])[
+]AT_YYLEX_DEFINE(["a"])[
int
main (void)
AT_CLEANUP
-## -------------------------------------------------------------------------- ##
-## User destructor for unresolved GLR semantic value. See ##
-## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00016.html>. ##
-## -------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## User destructor for unresolved GLR semantic value. See ##
+## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00016.html>. ##
+## ------------------------------------------------------------------------- ##
AT_SETUP([User destructor for unresolved GLR semantic value])
;
%%
-]AT_YYLEX_DEFINE(a)[
]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE(["a"])[
int
main (void)
{
AT_CLEANUP
-## -------------------------------------------------------------------------- ##
-## User destructor after an error during a split parse. See ##
-## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00029.html>. ##
-## -------------------------------------------------------------------------- ##
+## ------------------------------------------------------------------------- ##
+## User destructor after an error during a split parse. See ##
+## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00029.html>. ##
+## ------------------------------------------------------------------------- ##
AT_SETUP([User destructor after an error during a split parse])
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)
{
## ------------------------------------------------------------------------- ##
-## Duplicated user destructor for lookahead. See ##
+## Duplicated user destructor for lookahead. See ##
## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00035.html>. ##
## ------------------------------------------------------------------------- ##
#include <stdlib.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
- ]AT_YYERROR_DECLARE[
%}
%token T_CONSTANT
## ------------------------------------------------------------------------- ##
-## No users destructors if stack 0 deleted. See ##
+## No users destructors if stack 0 deleted. See ##
## <http://lists.gnu.org/archive/html/bison-patches/2005-09/msg00109.html>. ##
## ------------------------------------------------------------------------- ##
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])
;
%%
-
]AT_YYERROR_DEFINE[
-static int
-yylex (void)
-{
- static int called;
- if (called++)
- abort ();
- return 0;
-}
+]AT_YYLEX_DEFINE[
int
main (void)
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])
%%
]AT_YYERROR_DEFINE[
-]AT_YYLEX_DEFINE([a])[
+]AT_YYLEX_DEFINE(["a"])[
int
main (void)
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])
%{
# include <stdlib.h>
+# include <assert.h>
static int merge (YYSTYPE, YYSTYPE);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
]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)
%{
#include <stdio.h>
+ #include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
%%
]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)
AT_CLEANUP
-## ------------------------------------------------------------------------- ##
-## Incorrect lookahead during nondeterministic GLR. ##
-## ------------------------------------------------------------------------- ##
+## ------------------------------------------------- ##
+## Incorrect lookahead during nondeterministic GLR. ##
+## ------------------------------------------------- ##
AT_SETUP([Incorrect lookahead during nondeterministic GLR])
%{
#include <stdlib.h>
#include <stdio.h>
+ #include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
{
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';
AT_CLEANUP
-## ------------------------------------------------------------------------- ##
-## Leaked semantic values when reporting ambiguity. ##
-## ------------------------------------------------------------------------- ##
+## ------------------------------------------------- ##
+## Leaked semantic values when reporting ambiguity. ##
+## ------------------------------------------------- ##
AT_SETUP([Leaked semantic values when reporting ambiguity])
ambiguity2: ;
%%
-
]AT_YYERROR_DEFINE[
-static int
-yylex (void)
-{
- static int called;
- if (called++)
- abort ();
- return 0;
-}
+]AT_YYLEX_DEFINE[
int
main (void)
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])
%{
# include <stdlib.h>
+# include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static int lookahead_value = 0;
%%
]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)
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
%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
empty2: ;
%%
+# include <assert.h>
-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;
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
-## -------------------------------------------------------------##
-## Missed %merge type warnings when LHS type is declared later. ##
-## -------------------------------------------------------------##
+## ------------------------------------------------------------- ##
+## Missed %merge type warnings when LHS type is declared later. ##
+## ------------------------------------------------------------- ##
AT_SETUP([Missed %merge type warnings when LHS type is declared later])
%{
#include <stdlib.h>
]AT_YYERROR_DECLARE[
- static int yylex ();
+ ]AT_YYLEX_DECLARE[
%}
%union {
%type <type3> sym3;
%%
-
]AT_YYERROR_DEFINE[
-]AT_YYLEX_DEFINE()[
+]AT_YYLEX_DEFINE[
int
main (void)
{
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr18.c glr-regr18.y]], 1, [],
-[glr-regr18.y:26.18-24: result type clash on merge function 'merge': <type2> != <type1>
-glr-regr18.y:25.18-24: previous declaration
-glr-regr18.y:27.13-19: result type clash on merge function 'merge': <type3> != <type2>
-glr-regr18.y:26.18-24: previous declaration
+[glr-regr18.y:26.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
+glr-regr18.y:25.18-24: previous declaration
+glr-regr18.y:27.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
+glr-regr18.y:26.18-24: previous declaration
])
AT_CLEANUP
b: 'b';
d: /* nada. */;
%%
-]AT_YYLEX_DEFINE([abc])[
]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE(["abc"])[
int
main (void)
{