diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-12-31 07:20:49 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-12-31 08:07:25 +0100 |
commit | fbe5abd23d2047c593d81654263bf4dd331311ae (patch) | |
tree | e2d3dfb0ad87f9cdcf5c4ee86563c8333dde4aab /examples | |
parent | c09f2e4c7bcb242ca7f320be5777e7bd641f78ec (diff) | |
download | bison-fbe5abd23d2047c593d81654263bf4dd331311ae.tar.gz |
%merge: fix compatibility with api.value.type=union
Reported by Jot Dot.
https://lists.gnu.org/r/help-bison/2020-12/msg00014.html
* data/skeletons/glr.c, data/skeletons/glr2.cc (b4_call_merger): Use
the symbol's slot, not its type.
* examples/c/glr/c++-types.y: Use explicit per-symbol typing together
with api.value.type=union.
(yylex): Use yytoken_kind_t.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/c/glr/c++-types.y | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/examples/c/glr/c++-types.y b/examples/c/glr/c++-types.y index 33bf58a6..a760b600 100644 --- a/examples/c/glr/c++-types.y +++ b/examples/c/glr/c++-types.y @@ -31,7 +31,7 @@ typedef union Node Node; } -%define api.value.type {Node *} +%define api.value.type union %code { @@ -47,11 +47,11 @@ static Node *new_term (char *); static void free_node (Node *); static char *node_to_string (Node *); - static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1); + static Node *stmtMerge (YYSTYPE x0, YYSTYPE x1); static int location_print (FILE *yyo, YYLTYPE const * const yylocp); static void yyerror (YYLTYPE const * const llocp, const char *msg); - static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp); + static yytoken_kind_t yylex (YYSTYPE *lvalp, YYLTYPE *llocp); } %expect-rr 1 @@ -65,7 +65,8 @@ %glr-parser -%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID +%type <Node*> stmt expr decl declarator TYPENAME ID +%destructor { free_node ($$); } <Node*> %% @@ -152,7 +153,8 @@ void yyerror (YYLTYPE const * const llocp, const char *msg) fprintf (stderr, ": %s\n", msg); } -int yylex (YYSTYPE *lvalp, YYLTYPE *llocp) +yytoken_kind_t +yylex (YYSTYPE *lvalp, YYLTYPE *llocp) { static int lineNum = 1; static int colNum = 0; @@ -178,7 +180,7 @@ int yylex (YYSTYPE *lvalp, YYLTYPE *llocp) break; default: { - int tok; + yytoken_kind_t tok; llocp->first_line = llocp->last_line = lineNum; llocp->first_column = colNum; if (isalpha (c)) @@ -197,14 +199,21 @@ int yylex (YYSTYPE *lvalp, YYLTYPE *llocp) ungetc (c, stdin); buffer[i++] = 0; - tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; - *lvalp = new_term (strcpy (malloc (i), buffer)); + if (isupper ((unsigned char) buffer[0])) + { + tok = TYPENAME; + lvalp->TYPENAME = new_term (strcpy (malloc (i), buffer)); + } + else + { + tok = ID; + lvalp->ID = new_term (strcpy (malloc (i), buffer)); + } } else { colNum += 1; tok = c; - *lvalp = NULL; } llocp->last_column = colNum-1; return tok; @@ -289,8 +298,8 @@ node_to_string (Node *node) } -static YYSTYPE +static Node* stmtMerge (YYSTYPE x0, YYSTYPE x1) { - return new_nterm ("<OR>(%s,%s)", x0, x1, NULL); + return new_nterm ("<OR>(%s,%s)", x0.stmt, x1.stmt, NULL); } |