bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %union foo bar baz and others { ... }


From: Paul Eggert
Subject: Re: %union foo bar baz and others { ... }
Date: 22 Jan 2003 00:18:30 -0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2

> From: Akim Demaille <address@hidden>
> Date: Tue, 21 Jan 2003 13:58:23 +0100

> But there is some miscommunication here: I am struggling against
> anything between %union and {, I am *not* referring to what Bison puts
> between union and {.  I ask for the removal of the code that adds this
> feature.

OK, here is a proposed patch to do that.

This patch does not reverse all of the 2002-12-24 patch described in
<http://mail.gnu.org/archive/html/bison-patches/2002-12/msg00015.html>.
Some of the older patch fixes some POSIX conformance issues with
YYSTYPE, and some of it removes current_braced_code which was marked
as a "dirty hack".  This patch does not affect those changes.

I guess that you may have expected a patch that simplifies scan-gram.l
further, but I don't see an easy way of doing this without
resurrecting the current_braced_code "dirty hack", and to some extent
that resurrection would be a cure worse than the disease.

2003-01-22  Paul Eggert  <address@hidden>

        %union directives no longer can have a tag before the `{', e.g.,
        `%union foo {...}' is no longer allowed.  The union tag YYSTYPE is
        always used instead.  This undoes part of the 2002-12-24 patch.
        * bison.texinfo (Union Decl): Document this.
        * NEWS: Likewise.
        * data/glr.c (YYSTYPE): Always use "union YYSTYPE".
        * data/yacc.c (YYSTYPE): Likewise.
        * src/scan-gram.l (<SC_PRE_CODE>): Don't allow a tag between
        %union and {.

Index: NEWS
===================================================================
RCS file: /cvsroot/bison/bison/NEWS,v
retrieving revision 1.89
diff -p -u -r1.89 NEWS
--- NEWS        13 Jan 2003 06:41:28 -0000      1.89
+++ NEWS        22 Jan 2003 08:07:40 -0000
@@ -3,6 +3,10 @@ Bison News
 
 Changes in version 1.875a:
 
+* %union directives no longer can have a tag before the `{', e.g.,
+  `%union foo {...}' is no longer allowed.  The union tag YYSTYPE is
+  always used instead.
+
 * %expect-count violations are now just warnings, not errors, for
   compatibility with Bison 1.75 and earlier (when there are
   reduce/reduce conflicts) and with Bison 1.30 and earlier (when there
@@ -69,7 +73,11 @@ Changes in version 1.875, 2003-01-01:
   - %union directives can now have a tag before the `{', e.g., the
     directive `%union foo {...}' now generates the C code
     `typedef union foo { ... } YYSTYPE;'; this is for Yacc compatibility.
-    The default union tag is `YYSTYPE', for compatibility with Solaris 9 Yacc.
+    [However this change was reverted in Bison 1.875a, as it was a
+    hassle to maintain and it was largely unnecessary due to the next
+    change.]
+
+  - The default union tag is `YYSTYPE', for compatibility with Solaris 9 Yacc.
     For consistency, YYLTYPE's struct tag is now `YYLTYPE' not `yyltype'.
     This is for compatibility with both Yacc and Bison 1.35.
 
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.49
diff -p -u -r1.49 glr.c
--- data/glr.c  3 Jan 2003 14:32:35 -0000       1.49
+++ data/glr.c  22 Jan 2003 08:07:41 -0000
@@ -182,7 +182,7 @@ b4_pre_prologue[
 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
 ]m4_ifdef([b4_stype],
 [b4_syncline([b4_stype_line], [b4_filename])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+typedef union YYSTYPE b4_stype YYSTYPE;
 /* Line __line__ of glr.c.  */
 b4_syncline(address@hidden@], address@hidden@])],
 [typedef int YYSTYPE;])[
@@ -1957,7 +1957,7 @@ b4_token_defines(b4_tokens)
 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
 m4_ifdef([b4_stype],
 [b4_syncline([b4_stype_line], [b4_filename])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+typedef union YYSTYPE b4_stype YYSTYPE;
 /* Line __line__ of glr.c.  */
 b4_syncline(address@hidden@], address@hidden@])],
 [typedef int YYSTYPE;])
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.51
diff -p -u -r1.51 yacc.c
--- data/yacc.c 22 Jan 2003 06:38:32 -0000      1.51
+++ data/yacc.c 22 Jan 2003 08:07:41 -0000
@@ -185,7 +185,7 @@ b4_location_if([#define yylloc b4_prefix
 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
 ]m4_ifdef([b4_stype],
 [b4_syncline([b4_stype_line], [b4_filename])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+typedef union YYSTYPE b4_stype YYSTYPE;
 /* Line __line__ of yacc.c.  */
 b4_syncline(address@hidden@], address@hidden@])],
 [typedef int YYSTYPE;])[
@@ -1208,7 +1208,7 @@ b4_token_defines(b4_tokens)
 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
 m4_ifdef([b4_stype],
 [b4_syncline([b4_stype_line], [b4_filename])
-typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
+typedef union YYSTYPE b4_stype YYSTYPE;
 /* Line __line__ of yacc.c.  */
 b4_syncline(address@hidden@], address@hidden@])],
 [typedef int YYSTYPE;])
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.100
diff -p -u -r1.100 bison.texinfo
--- doc/bison.texinfo   13 Jan 2003 06:41:29 -0000      1.100
+++ doc/bison.texinfo   22 Jan 2003 08:07:43 -0000
@@ -1925,7 +1925,8 @@ These features allow semantic values to 
 (@pxref{Multiple Types, ,More Than One Value Type}).
 
 The @code{%union} declaration specifies the entire list of possible types;
-this is instead of defining @code{YYSTYPE}.  The allowable types are now
+it causes Bison to generate code that defines @code{YYSTYPE}, so you
+need not define @code{YYSTYPE} yourself.  The allowable types are now
 double-floats (for @code{exp} and @code{NUM}) and pointers to entries in
 the symbol table.  @xref{Union Decl, ,The Collection of Value Types}.
 
@@ -3423,21 +3424,14 @@ This says that the two alternative types
 in the @code{%token} and @code{%type} declarations to pick one of the types
 for a terminal or nonterminal symbol (@pxref{Type Decl, ,Nonterminal Symbols}).
 
-As an extension to @acronym{POSIX}, a tag is allowed after the
address@hidden  For example:
-
address@hidden
address@hidden
-%union value @{
-  double val;
-  symrec *tptr;
address@hidden
address@hidden group
address@hidden example
-
-specifies the union tag @code{value}, so the corresponding C type is
address@hidden value}.  If you do not specify a tag, it defaults to
address@hidden
+A @samp{%union} declaration causes Bison to generate a C type of the
+form @samp{union YYSTYPE @{ @var{members} @}}.  This occurrence of
address@hidden is a union tag, and is distinct from the standard
address@hidden typedef.  Some Yacc implementations allow an identifier
+between @samp{%union} and @address@hidden to specify the union tag.  Other
+Yacc implementations generate the union tag @samp{YYSTYPE} by default,
+as Bison does.  There is no standard for the union tag, so portable
+code should not assume any particular tag.
 
 Note that, unlike making a @code{union} declaration in C, you need not write
 a semicolon after the closing brace.
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.54
diff -p -u -r1.54 scan-gram.l
--- src/scan-gram.l     31 Dec 2002 02:26:51 -0000      1.54
+++ src/scan-gram.l     22 Jan 2003 08:07:44 -0000
@@ -1,6 +1,6 @@
 /* Bison Grammar Scanner                             -*- C -*-
 
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -502,33 +502,25 @@ splice     (\\[ \f\t\v]*\n)*
 
   /*---------------------------------------------------------------.
   | Scanning after %union etc., possibly followed by white space.  |
-  | For %union only, allow arbitrary C code to appear before the   |
-  | following brace, as an extension to POSIX.                    |
   `---------------------------------------------------------------*/
 
 <SC_PRE_CODE>
 {
-  . {
-    bool valid = yytext[0] == '{' || token_type == PERCENT_UNION;
-    scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0);
-    yyless (0);
+  "{" {
+    STRING_GROW;
+    braces_level = 0;
+    code_start = loc->start;
+    BEGIN SC_BRACED_CODE;
+  }
 
-    if (valid)
-      {
-       braces_level = -1;
-       code_start = loc->start;
-       BEGIN SC_BRACED_CODE;
-      }
-    else
-      {
-       complain_at (*loc, _("missing `{' in `%s'"),
-                    token_name (token_type));
-       obstack_sgrow (&obstack_for_string, "{}");
-       STRING_FINISH;
-       val->chars = last_string;
-       BEGIN INITIAL;
-       return token_type;
-      }
+  . {
+    complain_at (*loc, _("missing `{' in `%s'"),
+                token_name (token_type));
+    obstack_sgrow (&obstack_for_string, "{}");
+    STRING_FINISH;
+    val->chars = last_string;
+    BEGIN INITIAL;
+    return token_type;
   }
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]