bison-patches
[Top][All Lists]
Advanced

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

Re: yytype_FOO (was: [PATCH 0/6] api.value.type support)


From: Akim Demaille
Subject: Re: yytype_FOO (was: [PATCH 0/6] api.value.type support)
Date: Mon, 25 Mar 2013 09:21:44 +0100

Le 24 mars 2013 à 22:07, Joel E. Denny <address@hidden> a écrit :

> Hi Akim,

Hi Joel!

> Sorry for my slow response.

Slow news is good news :)

> All this seems fine to me.  How did you decide to address the yacc #define 
> issue?  I suppose it's OK to break with perfect yacc compatibility when 
> using a non-yacc feature.

Autoconf was modified to use YACC='bison -o y.tab.c' instead of
YACC='bison -y'.  It has the same effect, but it does not enable
-Wyacc.  So eventually, users won't even notice.  Meanwhile I
will recommend, in NEWS, that users (of older Autoconfs) pass
-Wno-yacc to AM_YFLAGS.

I will merge the following diffs in the api.value.type branch,
in the appropriate commits.

Given that api.token.prefix actually applies to all symbols,
I am considering renaming it api.symbol.prefix.  It has never
been released, so it's not too late.

diff --git a/data/bison.m4 b/data/bison.m4
index f54ff5f..7cc0fa6 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -347,6 +347,7 @@ b4_define_flag_if([yacc])               # Whether POSIX 
Yacc is emulated.
 #   Whether the symbol has an id.
 # - id: string
 #   If has_id, the id.  Guaranteed to be usable as a C identifier.
+#   Prefixed by api.token.prefix if defined.
 # - tag: string.
 #   A representat of the symbol.  Can be 'foo', 'foo.id', '"foo"' etc.
 # - user_number: integer
diff --git a/data/c.m4 b/data/c.m4
index 1814877..fa2984d 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -510,9 +510,9 @@ b4_locations_if([, yylocationp])[]b4_user_args[);
 # instead of the type name.
 m4_define([b4_symbol_type_register],
 [m4_define([b4_symbol($1, type_tag)],
-           [yytype_[]b4_symbol_if([$1], [has_id],
-                                  [b4_symbol([$1], [id])],
-                                  [b4_symbol([$1], [number])])])dnl
+           [b4_symbol_if([$1], [has_id],
+                         [b4_symbol([$1], [id])],
+                         [yytype_[]b4_symbol([$1], [number])])])dnl
 m4_append([b4_user_union_members],
 m4_expand([
   b4_symbol_tag_comment([$1])dnl
diff --git a/doc/bison.texi b/doc/bison.texi
index 1109a6f..3066ffb 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -2671,7 +2671,7 @@ yylex (void)
   if (c == '.' || isdigit (c))
     @{
       ungetc (c, stdin);
-      scanf ("%lf", &yylval.yytype_NUM);
+      scanf ("%lf", &yylval.NUM);
       return NUM;
     @}
 @end group
@@ -2679,7 +2679,7 @@ yylex (void)
 
 @noindent
 Bison generated a definition of @code{YYSTYPE} with a member named
address@hidden to store value of @code{NUM} symbols.
address@hidden to store value of @code{NUM} symbols.
 
 @comment file: mfcalc.y: 3
 @example
@@ -3766,13 +3766,13 @@ For example:
 generates an appropriate value of @code{YYSTYPE} to support each symbol
 type.  The name of the member of @code{YYSTYPE} for tokens than have a
 declared identifier @var{id} (such as @code{INT} and @code{ID} above, but
-not @code{'n'}) is @address@hidden  The other symbols have
-unspecified names on which you should not depend; instead, relying on C
-casts to access the semantic value with the appropriate type:
+not @code{'n'}) is @address@hidden  The other symbols have unspecified
+names on which you should not depend; instead, relying on C casts to access
+the semantic value with the appropriate type:
 
 @example
 /* For an "integer".  */
-yylval.yytype_INT = 42;
+yylval.INT = 42;
 return INT;
 
 /* For an 'n', also declared as int.  */
@@ -3780,10 +3780,20 @@ return INT;
 return 'n';
 
 /* For an "identifier".  */
-yylval.yytype_ID = "42";
-return IDENTIFIER;
+yylval.ID = "42";
+return ID;
 @end example
 
+If the @code{%define} variable @code{api.token.prefix} is defined
+(@pxref{%define Summary,,api.token.prefix}), then it is also used to prefix
+the union member names.  For instance, with @samp{%define api.token.prefix
+TOK_}:
+
address@hidden
+/* For an "integer".  */
+yylval.TOK_INT = 42;
+return TOK_INT;
address@hidden example
 
 This feature is new, and user feedback would be most welcome.
 
@@ -5891,8 +5901,13 @@ and @code{TOK_ERROR} in the generated source files.  In 
particular, the
 scanner must use these prefixed token names, while the grammar itself
 may still use the short names (as in the sample rule given above).  The
 generated informational files (@file{*.output}, @file{*.xml},
address@hidden) are not modified by this prefix.  See @ref{Calc++ Parser}
-and @ref{Calc++ Scanner}, for a complete example.
address@hidden) are not modified by this prefix.
+
+Bison also prefixes the generated member names of the semantic value union.
address@hidden Generation,, Generating the Semantic Value Type}, for more
+details.
+
+See @ref{Calc++ Parser} and @ref{Calc++ Scanner}, for a complete example.
 
 @item Accepted Values:
 Any string.  Should be a valid identifier prefix in the target language,
diff --git a/tests/types.at b/tests/types.at
index fd0ed65..eb5b358 100644
--- a/tests/types.at
+++ b/tests/types.at
@@ -176,11 +176,11 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], 
[glr.cc]],
           [ONE TWO THREE { printf ("%d %2.1f %2.1f\n", $1, $2, $3); }],
           [{ 101, 102, 103, EOF }],
           [if (res == 101)
-             AT_VAL.yytype_ONE = 10;
+             AT_VAL.ONE = 10;
            else if (res == 102)
-             AT_VAL.yytype_TWO = .2f;
+             AT_VAL.TWO = .2f;
            else if (res == 103)
-             AT_VAL.yytype_THREE = 3.3f],
+             AT_VAL.THREE = 3.3f],
           [10 0.2 3.3])
 
   # A Bison-defined variant, for lalr1.cc only.




reply via email to

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