X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/adc90f13abe835bb5b6cf23ec00e516877c3f5d7..c7e8607f6b908246335f2caf3553dbd741f2279f:/tests/glr-regression.at?ds=sidebyside diff --git a/tests/glr-regression.at b/tests/glr-regression.at index a2d3ce76..966730b8 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -338,7 +338,8 @@ AT_CLEANUP AT_SETUP([Duplicate representation of merged trees]) AT_DATA_GRAMMAR([glr-regr4.y], -[[%union { char *ptr; } +[[ +%union { char *ptr; } %type S A A1 A2 B %glr-parser @@ -347,7 +348,7 @@ AT_DATA_GRAMMAR([glr-regr4.y], #include #include 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); %} @@ -386,10 +387,11 @@ main (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; } @@ -398,7 +400,8 @@ static char * 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; } @@ -406,7 +409,7 @@ merge (YYSTYPE s1, YYSTYPE s2) static void yyerror (char const *msg) { - printf ("%s\n", msg); + fprintf (stderr, "%s\n", msg); } ]]) @@ -422,16 +425,17 @@ AT_CHECK([[./glr-regr4]], 0, AT_CLEANUP -## ---------------------------------------------------------------------- ## -## User destructor for unresolved GLR semantic value ## -## Thanks to Joel E. Denny for this test; see ## -## . ## -## ---------------------------------------------------------------------- ## +## ------------------------------------------------------------------------- ## +## User destructor for unresolved GLR semantic value ## +## Thanks to Joel E. Denny for this test; see ## +## . ## +## ------------------------------------------------------------------------- ## AT_SETUP([User destructor for unresolved GLR semantic value]) AT_DATA_GRAMMAR([glr-regr5.y], -[[%{ +[[ +%{ #include #include static void yyerror (char const *); @@ -470,7 +474,7 @@ yylex (void) static void yyerror (char const *msg) { - printf ("%s\n", msg); + fprintf (stderr, "%s\n", msg); } int @@ -485,8 +489,150 @@ AT_CHECK([[bison -o glr-regr5.c glr-regr5.y]], 0, [], ]) AT_COMPILE([glr-regr5]) -AT_CHECK([[./glr-regr5]], 0, +AT_CHECK([[./glr-regr5]], 0, [], +[syntax is ambiguous +]) + +AT_CLEANUP + + +## ------------------------------------------------------------------------- ## +## User destructor after an error during a split parse ## +## Thanks to Joel E. Denny for this test; see ## +## . ## +## ------------------------------------------------------------------------- ## + +AT_SETUP([User destructor after an error during a split parse]) + +AT_DATA_GRAMMAR([glr-regr6.y], +[[ +%{ + #include + #include + static void yyerror (char const *); + static int yylex (void); +%} + +%glr-parser +%union { int value; } +%type 'a' + +%destructor { + printf ("Destructor called.\n"); +} 'a' + +%% + +start: 'a' | 'a' ; + +%% + +static int +yylex (void) +{ + static char const *input = "a"; + return *input++; +} + +static void +yyerror (char const *msg) +{ + fprintf (stderr, "%s\n", msg); +} + +int +main (void) +{ + return yyparse () != 1; +} +]]) + +AT_CHECK([[bison -o glr-regr6.c glr-regr6.y]], 0, [], +[glr-regr6.y: conflicts: 1 reduce/reduce +]) +AT_COMPILE([glr-regr6]) + +AT_CHECK([[./glr-regr6]], 0, +[Destructor called. +], [syntax is ambiguous ]) AT_CLEANUP + + +## ------------------------------------------------------------------------- ## +## Duplicated user destructor for lookahead ## +## Thanks to Joel E. Denny for this test; see ## +## . ## +## ------------------------------------------------------------------------- ## + +AT_SETUP([Duplicated user destructor for lookahead]) + +AT_DATA_GRAMMAR([glr-regr7.y], +[[ +%{ + #include + #include + static void yyerror (char const *); + static int yylex (void); + #define YYSTACKEXPANDABLE 0 +%} + +%glr-parser +%union { int *count; } +%type '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