* data/c++.m4, data/lalr1.cc (parser::symbol_type): Change the
        constructor to take a token_type instead of the (internal) symbol
        number.
        Call yytranslate_.
        * data/variant.hh (b4_symbol_constructor_define_): Therefore,
        don't call yytranslate_ here.

This factors loads of repeated code. In my case for instance, I have, in the generated parser:

  // Implementation of make_symbol for each symbol type.
  parser::symbol_type
  parser::make_EOF (const location_type& l)
  {
    return symbol_type (yytranslate_ (token::TOK_EOF), l);
  }

  parser::symbol_type
  parser::make___HERE__ (const location_type& l)
  {
    return symbol_type (yytranslate_ (token::TOK___HERE__), l);
  }

  parser::symbol_type
  parser::make_EQ (const location_type& l)
  {
    return symbol_type (yytranslate_ (token::TOK_EQ), l);
  }

  parser::symbol_type
  parser::make_BREAK (const location_type& l)
  {
    return symbol_type (yytranslate_ (token::TOK_BREAK), l);
  }

  parser::symbol_type
  parser::make_CASE (const location_type& l)
  {
    return symbol_type (yytranslate_ (token::TOK_CASE), l);
  }

it now reads:


  // Implementation of make_symbol for each symbol type.
  parser::symbol_type
  parser::make_EOF (const location_type& l)
  {
    return symbol_type (token::TOK_EOF, l);
  }

  parser::symbol_type
  parser::make___HERE__ (const location_type& l)
  {
    return symbol_type (token::TOK___HERE__, l);
  }

  parser::symbol_type
  parser::make_EQ (const location_type& l)
  {
    return symbol_type (token::TOK_EQ, l);
  }

  parser::symbol_type
  parser::make_BREAK (const location_type& l)
  {
    return symbol_type (token::TOK_BREAK, l);
  }

  parser::symbol_type
  parser::make_CASE (const location_type& l)
  {
    return symbol_type (token::TOK_CASE, l);
  }

I suppose it does have an impact of the object file, but I have not checked.

From 2b08bcebf082a2417ef5706b5ae0664ce844f16e Mon Sep 17 00:00:00 2001
From: Akim Demaille <[email protected]>
Date: Wed, 9 Sep 2009 23:09:22 +0200
Subject: [PATCH] lalr1.cc: factor the yytranslate_ invocation in make_SYMBOLS.

        * data/c++.m4, data/lalr1.cc (parser::symbol_type): Change the
        constructor to take a token_type instead of the (internal) symbol
        number.
        Call yytranslate_.
        * data/variant.hh (b4_symbol_constructor_define_): Therefore,
        don't call yytranslate_ here.
---
 ChangeLog       |   10 ++++++++++
 data/c++.m4     |   19 ++++++++++---------
 data/lalr1.cc   |    4 ++--
 data/variant.hh |    2 +-
 4 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 70e89b7..1182da7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-09-16  Akim Demaille  <[email protected]>
 
+       lalr1.cc: factor the yytranslate_ invocation in make_SYMBOLS.
+       * data/c++.m4, data/lalr1.cc (parser::symbol_type): Change the
+       constructor to take a token_type instead of the (internal) symbol
+       number.
+       Call yytranslate_.
+       * data/variant.hh (b4_symbol_constructor_define_): Therefore,
+       don't call yytranslate_ here.
+
+2009-09-16  Akim Demaille  <[email protected]>
+
        TODO: statistics.
        * TODO (Figures): New.
 
diff --git a/data/c++.m4 b/data/c++.m4
index 3157e47..22b3375 100644
--- a/data/c++.m4
+++ b/data/c++.m4
@@ -178,21 +178,22 @@ m4_define([b4_public_types_declare],
       /// Default constructor.
       inline symbol_type ();
 
-      /// Constructor.
-      inline symbol_type (]b4_args([int t],
+      /// Constructor for tokens with semantic value.
+      inline symbol_type (]b4_args([token_type t],
                                    [const semantic_type& v],
                                    b4_locations_if([const location_type& 
l]))[);
 
-      inline symbol_type (]b4_args([int t],
+      /// Constructor for valueless tokens.
+      inline symbol_type (]b4_args([token_type t],
                                    b4_locations_if([const location_type& 
l]))[);
 
       /// The symbol type.
       int type;
 
-      /// Return the type corresponding to this state.
+      /// The symbol type.
       inline int type_get_ () const;
 
-      /// Its token.
+      /// The token.
       inline token_type token () const;
     };
 ]b4_symbol_constructor_declare])
@@ -269,20 +270,20 @@ m4_define([b4_public_types_define],
 
   inline
   ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
-                [int t],
+                [token_type t],
                 b4_locations_if([const location_type& l]))[)
     : super_type (]b4_locations_if([l])[)
-    , type (t)
+    , type (yytranslate_ (t))
   {
   }
 
   inline
   ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
-                 [int t],
+                 [token_type t],
                  [const semantic_type& v],
                  b4_locations_if([const location_type& l]))[)
     : super_type (v]b4_locations_if([, l])[)
-    , type (t)
+    , type (yytranslate_ (t))
   {
   }
 
diff --git a/data/lalr1.cc b/data/lalr1.cc
index ac2fa35..1a2777e 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -29,7 +29,7 @@ m4_define([b4_integral_parser_table_declare],
 ])
 
 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
-# ---------------------------------------------
+# -------------------------------------------------------------
 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
 m4_define([b4_integral_parser_table_define],
 [  const b4_int_type_for([$2])
@@ -321,7 +321,7 @@ do {                                                        
    \
       /// The state.
       state_type state;
 
-      /// Return the type corresponding to this state.
+      /// The type (corresponding to \a state).
       inline int type_get_ () const;
     };
 
diff --git a/data/variant.hh b/data/variant.hh
index ae26f5b..31af62b 100644
--- a/data/variant.hh
+++ b/data/variant.hh
@@ -262,7 +262,7 @@ b4_args(b4_symbol_if([$1], [has_type],
                      [const b4_symbol([$1], [type])& v]),
         b4_locations_if([const location_type& l])))
   {
-    return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [id]))],
+    return symbol_type (b4_args([token::b4_symbol([$1], [id])],
                                 b4_symbol_if([$1], [has_type], [v]),
                                 b4_locations_if([l])));
   }
-- 
1.6.4.3

Reply via email to