diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2021-09-07 07:07:31 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2021-09-12 12:03:58 +0200 |
commit | 7c47598d4f7c290b7127e329c09750dab0975eab (patch) | |
tree | 435c3855e746e589087a33b29d01da81fec36975 /tests | |
parent | fdaedc780af0dd678a4f4fa3175a201a553be20a (diff) | |
download | bison-7c47598d4f7c290b7127e329c09750dab0975eab.tar.gz |
glr2.cc: start the transition to using symbol_type
Currently glr2.cc uses three variables/struct members to denote the
symbols' kind (or state), value and location. lalr1.cc has two types
for "complete" symbols: symbol_type and stack_symbol_type. Let's use
that model in glr2.cc too.
For a start use yyla (a symbol_type) to denote the lookahead, instead
of the triple yytoken, yylval and yylloc. This will make easier the
introduction of the "context" subclass, used in parse.error=custom.
It simplifies the code in several places. For instance from:
symbol_kind_type yytoken_current = this->yytoken;]b4_variant_if([[
value_type yylval_current;
]b4_symbol_variant([this->yytoken],
[yylval_current], [move], [this->yylval])], [[
value_type yylval_current = this->yylval;]])[]b4_locations_if([
location_type yylloc_current = this->yylloc;])[
to:
symbol_type yyla_current = std::move (this->yyla);
* data/skeletons/glr2.cc (yytoken, yylval, yylloc): Replace by...
(yyla): this.
Adjust all dependencies.
(yyloc_default): Remove, unused.
* tests/c++.at, tests/glr-regression.at, tests/types.at: C++11 is
required for glr2.cc.
Adjust to changes in glr2.cc.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/c++.at | 1 | ||||
-rw-r--r-- | tests/glr-regression.at | 26 | ||||
-rw-r--r-- | tests/types.at | 1 |
3 files changed, 17 insertions, 11 deletions
diff --git a/tests/c++.at b/tests/c++.at index 0472c47c..a2c46c2c 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -1031,6 +1031,7 @@ yylex (yy::parser::value_type *lval) AT_BISON_CHECK([[-o input.cc input.yy]]) AT_FOR_EACH_CXX([ + AT_GLR2_CC_IF([AT_REQUIRE_CXX_STD(11, [echo "$at_std not supported"; continue])]) AT_LANG_COMPILE([[input]], [[input.cc scan.cc]]) # Leave enough valid tokens to make sure we recovered from the diff --git a/tests/glr-regression.at b/tests/glr-regression.at index eaba687d..2cd09468 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -42,13 +42,12 @@ yyparse () # -------------------------- m4_define([AT_PRINT_LOOKAHEAD_DECLARE], [AT_GLR2_CC_IF( -[[ static void - print_lookahead (int yytoken, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp, - char const *reduction); +[[static void + print_lookahead (yy::parser::symbol_type yylookahead, char const *reduction); #define PRINT_LOOKAHEAD(Msg) \ - print_lookahead (yytoken, &yylval, &yylloc, Msg) + print_lookahead (yyla, Msg) ]], -[[ static void +[[static void print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp, char const *reduction); #define PRINT_LOOKAHEAD(Msg) \ @@ -60,8 +59,7 @@ m4_define([AT_PRINT_LOOKAHEAD_DECLARE], m4_define([AT_PRINT_LOOKAHEAD_DEFINE], [AT_GLR2_CC_IF( [[static void -print_lookahead (int yytoken, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp, - char const *reduction) +print_lookahead (yy::parser::symbol_type yylookahead, char const *reduction) ]], [[static void print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp, @@ -80,11 +78,12 @@ print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp, // | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 117 | : '?'; // | ~~~~~ + int yytoken = yylookahead.kind (); int yychr = yytoken == yy::parser::symbol_kind::S_YYEMPTY ? -2 : yytoken == yy::parser::symbol_kind::S_YYEOF ? 0 - : yytoken == yy::parser::yytranslate_ ('a') ? 'a' - : yytoken == yy::parser::yytranslate_ ('b') ? 'b' + : yytoken == yy::parser::symbol_kind::S_3_a_ ? 'a' + : yytoken == yy::parser::symbol_kind::S_4_b_ ? 'b' : '?'; ]])[ printf ("%s:\n yychar=", reduction); @@ -94,12 +93,17 @@ print_lookahead (int yychr, ]AT_YYSTYPE[ *yylvalp, ]AT_YYLTYPE[ *yyllocp, printf ("YYEOF"); else { - printf ("'%c', yylval='", yychr); + printf ("'%c', yylval='", yychr);]AT_GLR2_CC_IF([[ + if (yylookahead.value.value > ' ') + printf ("%c", yylookahead.value.value); + printf ("', yylloc=(%d,%d),(%d,%d)", + yylookahead.location.]AT_FIRST_LINE[, yylookahead.location.]AT_FIRST_COLUMN[, + yylookahead.location.]AT_LAST_LINE[, yylookahead.location.]AT_LAST_COLUMN[);]], [[ if (yylvalp->value > ' ') printf ("%c", yylvalp->value); printf ("', yylloc=(%d,%d),(%d,%d)", yyllocp->]AT_FIRST_LINE[, yyllocp->]AT_FIRST_COLUMN[, - yyllocp->]AT_LAST_LINE[, yyllocp->]AT_LAST_COLUMN[); + yyllocp->]AT_LAST_LINE[, yyllocp->]AT_LAST_COLUMN[);]])[ } printf ("\n"); } diff --git a/tests/types.at b/tests/types.at index 02a7d6e3..dcdf3feb 100644 --- a/tests/types.at +++ b/tests/types.at @@ -105,6 +105,7 @@ start: $3; ]]) AT_LANG_FOR_EACH_STD([ + AT_GLR2_CC_IF([AT_REQUIRE_CXX_STD(11, [echo "$at_std not supported"; continue])]) $7 AT_FULL_COMPILE([[test]]) AT_PARSER_CHECK([[test]], 0, [[$6 |