[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bison parse-gram.y union
From: |
Paul Eggert |
Subject: |
bison parse-gram.y union |
Date: |
Thu, 19 Jan 2006 13:39:34 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
(I installed this patch on Jan 3 but forgot to mention it on this
list. Sorry. Here's a belated report. The NEWS and doc fixes have
already been reported.)
twlevo <address@hidden> writes:
> parse-gram.y line 248, multiple %union statements
> are not detected and warned in input grammar.
>
> %union { int somenumber; }
> %union { char *somestring; }
Thanks for reporting this. POSIX allows this in the grammar for Yacc
grammars, but it doesn't give a semantics. Traditional yacc generates
garbage in this case. I think a nicer thing to do is to concatenate
the union bodies, so I installed this:
2006-01-03 Paul Eggert <address@hidden>
* data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c:
Allow multiple %union directives, whose contents concatenate.
* src/parse-gram.y (grammar_declaration): Likewise.
Use muscle_code_grow, so that we don't need stype_line any more.
All uses changed.
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.152
diff -p -u -r1.152 glr.c
--- data/glr.c 3 Jan 2006 19:12:55 -0000 1.152
+++ data/glr.c 3 Jan 2006 20:23:22 -0000
@@ -173,10 +173,11 @@ m4_define([b4_shared_declarations],
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
]m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_file_name])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+[typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])
+b4_stype
/* Line __line__ of glr.c. */
-b4_syncline(address@hidden@], address@hidden@])],
+b4_syncline(address@hidden@], address@hidden@])
+ YYSTYPE;],
[typedef int YYSTYPE;])[
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
Index: data/glr.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.cc,v
retrieving revision 1.10
diff -p -u -r1.10 glr.cc
--- data/glr.cc 3 Jan 2006 19:12:55 -0000 1.10
+++ data/glr.cc 3 Jan 2006 20:23:23 -0000
@@ -296,10 +296,11 @@ namespace yy
/// Symbol semantic values.
#if ! defined (YYSTYPE)
]m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_file_name])
- union semantic_type b4_stype;
+[ union semantic_type
+b4_stype
/* Line __line__ of lalr1.cc. */
-b4_syncline(address@hidden@], address@hidden@])],
+b4_syncline(address@hidden@], address@hidden@])
+ ;],
[ typedef int semantic_type;])[
#else
typedef YYSTYPE semantic_type;
Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.118
diff -p -u -r1.118 lalr1.cc
--- data/lalr1.cc 22 Dec 2005 13:01:50 -0000 1.118
+++ data/lalr1.cc 3 Jan 2006 20:23:23 -0000
@@ -2,7 +2,7 @@ m4_divert(-1)
# C++ skeleton for Bison
-# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2005, 2006 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
@@ -30,7 +30,7 @@ m4_divert(0)dnl
m4_if(b4_defines_flag, 0, [],
address@hidden @output_header_name@
b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
- [2002, 2003, 2004, 2005])
+ [2002, 2003, 2004, 2005, 2006])
dnl FIXME: This is wrong, we want computed header guards.
[
/* C++ LALR(1) parser skeleton written by Akim Demaille. */
@@ -104,10 +104,11 @@ namespace yy
/// Symbol semantic values.
#if ! defined (YYSTYPE)
]m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_file_name])
- union semantic_type b4_stype;
+[ union semantic_type
+b4_stype
/* Line __line__ of lalr1.cc. */
-b4_syncline(address@hidden@], address@hidden@])],
+b4_syncline(address@hidden@], address@hidden@])
+ ;],
[ typedef int semantic_type;])[
#else
typedef YYSTYPE semantic_type;
@@ -295,7 +296,7 @@ b4_error_verbose_if([, int tok])[);
])dnl
@output @output_parser_name@
b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
- [2002, 2003, 2004, 2005])
+ [2002, 2003, 2004, 2005, 2006])
m4_if(b4_prefix[], [yy], [],
[
// Take the name prefix into account.
@@ -1048,7 +1049,8 @@ b4_error_verbose_if([, int tok])[)
]b4_epilogue
dnl
@output b4_dir_prefix[]stack.hh
-b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
+b4_copyright([stack handling for Bison C++ parsers],
+ [2002, 2003, 2004, 2005, 2006])[
#ifndef BISON_STACK_HH
# define BISON_STACK_HH
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.127
diff -p -u -r1.127 yacc.c
--- data/yacc.c 3 Jan 2006 19:12:55 -0000 1.127
+++ data/yacc.c 3 Jan 2006 20:23:23 -0000
@@ -189,10 +189,11 @@ b4_location_if([#define yylloc b4_prefix
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
]m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_file_name])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+[typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])
+b4_stype
/* Line __line__ of yacc.c. */
-b4_syncline(address@hidden@], address@hidden@])],
+b4_syncline(address@hidden@], address@hidden@])
+ YYSTYPE;],
[typedef int YYSTYPE;])[
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
@@ -1508,10 +1509,11 @@ b4_token_enums_defines(b4_tokens)
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_file_name])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+[typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])
+b4_stype
/* Line __line__ of yacc.c. */
-b4_syncline(address@hidden@], address@hidden@])],
+b4_syncline(address@hidden@], address@hidden@])
+ YYSTYPE;],
[typedef int YYSTYPE;])
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
Index: src/parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.65
diff -p -u -r1.65 parse-gram.y
--- src/parse-gram.y 27 Dec 2005 17:50:00 -0000 1.65
+++ src/parse-gram.y 3 Jan 2006 20:23:23 -0000
@@ -247,9 +247,19 @@ grammar_declaration:
}
| "%union {...}"
{
+ char const *body = $1;
+
+ if (typed)
+ {
+ /* Concatenate the union bodies, turning the first one's
+ trailing '}' into '\n', and omitting the second one's '{'. */
+ char *code = muscle_find ("stype");
+ code[strlen (code) - 1] = '\n';
+ body++;
+ }
+
typed = true;
- MUSCLE_INSERT_INT ("stype_line", @1.start.line);
- muscle_insert ("stype", $1);
+ muscle_code_grow ("stype", body, @1);
}
| "%destructor {...}" symbols.1
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bison parse-gram.y union,
Paul Eggert <=