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.
This commit is contained in:
Akim Demaille
2021-09-07 07:07:31 +02:00
parent fdaedc780a
commit 7c47598d4f
4 changed files with 111 additions and 120 deletions

View File

@@ -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

View File

@@ -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");
}

View File

@@ -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