X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/71b00ed87431c17606afc2b44c9d320d347a76bc..cb3f7f335aa69ba3e6478fea8d4591f4f6d43bc5:/tests/actions.at diff --git a/tests/actions.at b/tests/actions.at index 371cf84f..4f7f5790 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -1,6 +1,7 @@ # Executing Actions. -*- Autotest -*- -# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 -# Free Software Foundation, Inc. + +# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, +# 2010 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +30,7 @@ AT_SETUP([Mid-rule actions]) # action. AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error verbose %debug %{ # include @@ -93,7 +94,7 @@ AT_CLEANUP AT_SETUP([Exotic Dollars]) AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error verbose %debug %{ # include @@ -557,7 +558,7 @@ m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR], $3 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4], -[%define error-verbose +[%define parse.error verbose %debug %verbose %locations @@ -588,7 +589,7 @@ AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union]) AT_SETUP([Default tagless %printer and %destructor]) AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error verbose %debug %locations %initial-action { @@ -706,7 +707,7 @@ AT_CLEANUP AT_SETUP([Default tagged and per-type %printer and %destructor]) AT_DATA_GRAMMAR([[input.y]], -[[%define error-verbose +[[%define parse.error verbose %debug %{ @@ -850,7 +851,7 @@ m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN], [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])]) AT_DATA_GRAMMAR([[input]]$1[[.y]], -[[%define error-verbose +[[%define parse.error verbose %debug %locations %initial-action { @@ -1408,3 +1409,74 @@ AT_MATCHES_CHECK([input.c], [[// TEST:Y:1 [;{}]*\n;\}$]], [[12]]) AT_MATCHES_CHECK([input.c], [[#define TEST_MACRO_N \\\n\[\]"broken\\" \$ \@ \$\$ \@\$ \[\];\\\nstring;"\}]], [[2]]) AT_CLEANUP + + +## -------------------------------------------------- ## +## Destroying lookahead assigned by semantic action. ## +## -------------------------------------------------- ## + +AT_SETUP([[Destroying lookahead assigned by semantic action]]) + +AT_DATA_GRAMMAR([input.y], +[[ +%code { + #include + #include + static void yyerror (char const *); + static int yylex (void); + #define USE(Var) +} + +%destructor { fprintf (stderr, "'a' destructor\n"); } 'a' +%destructor { fprintf (stderr, "'b' destructor\n"); } 'b' + +%% + +// In a previous version of Bison, yychar assigned by the semantic +// action below was not translated into yytoken before the lookahead was +// discarded and thus before its destructor (selected according to +// yytoken) was called in order to return from yyparse. This would +// happen even if YYACCEPT was performed in a later semantic action as +// long as only consistent states with default reductions were visited +// in between. However, we leave YYACCEPT in the same semantic action +// for this test in order to show that skeletons cannot simply translate +// immediately after every semantic action because a semantic action +// that has set yychar might not always return normally. Instead, +// skeletons must translate before every use of yytoken. +start: 'a' accept { USE($1); } ; +accept: /*empty*/ { + assert (yychar == YYEMPTY); + yychar = 'b'; + YYACCEPT; +} ; + +%% + +static void +yyerror (char const *msg) +{ + fprintf (stderr, "%s\n", msg); +} + +static int +yylex (void) +{ + static char const *input = "a"; + return *input++; +} + +int +main (void) +{ + return yyparse (); +} +]]) + +AT_BISON_CHECK([[-o input.c input.y]]) +AT_COMPILE([[input]]) +AT_PARSER_CHECK([[./input]], [[0]], [], +[['b' destructor +'a' destructor +]]) + +AT_CLEANUP