AT_SETUP([Duplicate representation of merged trees])
AT_DATA_GRAMMAR([glr-regr4.y],
-[[%union { char *ptr; }
+[[
+%union { char *ptr; }
%type <ptr> S A A1 A2 B
%glr-parser
#include <stdlib.h>
#include <string.h>
static char *merge (YYSTYPE, YYSTYPE);
- static char *make_value (char *, char *);
+ static char *make_value (char const *, char const *);
static void yyerror (char const *);
static int yylex (void);
%}
}
static char *
-make_value (char *parent, char *child)
+make_value (char const *parent, char const *child)
{
char const format[] = "%s <- %s";
- char *value = malloc (strlen (parent) + strlen (child) + sizeof format);
+ char *value =
+ (char *) malloc (strlen (parent) + strlen (child) + sizeof format);
sprintf (value, format, parent, child);
return value;
}
merge (YYSTYPE s1, YYSTYPE s2)
{
char const format[] = "merge{ %s and %s }";
- char *value = malloc (strlen (s1.ptr) + strlen (s2.ptr) + sizeof format);
+ char *value =
+ (char *) malloc (strlen (s1.ptr) + strlen (s2.ptr) + sizeof format);
sprintf (value, format, s1.ptr, s2.ptr);
return value;
}
AT_SETUP([User destructor for unresolved GLR semantic value])
AT_DATA_GRAMMAR([glr-regr5.y],
-[[%{
+[[
+%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
AT_SETUP([User destructor after an error during a split parse])
AT_DATA_GRAMMAR([glr-regr6.y],
-[[%{
+[[
+%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
])
AT_CLEANUP
+
+
+## ------------------------------------------------------------------------- ##
+## Duplicated user destructor for lookahead ##
+## Thanks to Joel E. Denny for this test; see ##
+## <http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00035.html>. ##
+## ------------------------------------------------------------------------- ##
+
+AT_SETUP([Duplicated user destructor for lookahead])
+
+AT_DATA_GRAMMAR([glr-regr7.y],
+[[
+%{
+ #include <stdio.h>
+ #include <stdlib.h>
+ static void yyerror (char const *);
+ static int yylex (void);
+ #define YYSTACKEXPANDABLE 0
+%}
+
+%glr-parser
+%union { int *count; }
+%type <count> 'a'
+
+%destructor {
+ if ((*$$)++)
+ fprintf (stderr, "Destructor called on same value twice.\n");
+} 'a'
+
+%%
+
+start:
+ stack1 start
+ | stack2 start
+ | /* empty */
+ ;
+stack1: 'a' ;
+stack2: 'a' ;
+
+%%
+
+static int
+yylex (void)
+{
+ yylval.count = malloc (sizeof (int));
+ if (!yylval.count)
+ {
+ fprintf (stderr, "Test inconclusive.\n");
+ exit (EXIT_FAILURE);
+ }
+ *yylval.count = 0;
+ return 'a';
+}
+
+static void
+yyerror (char const *msg)
+{
+ fprintf (stderr, "%s\n", msg);
+}
+
+int
+main (void)
+{
+ return yyparse ();
+}
+]])
+
+AT_CHECK([[bison -o glr-regr7.c glr-regr7.y]], 0, [],
+[glr-regr7.y: conflicts: 2 reduce/reduce
+])
+AT_COMPILE([glr-regr7])
+
+AT_CHECK([[exit 77; ./glr-regr7]], 2, [],
+[memory exhausted
+])
+
+AT_CLEANUP