bison-patches
[Top][All Lists]
Advanced

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

[PATCH] %define token.prefix.


From: Akim Demaille
Subject: [PATCH] %define token.prefix.
Date: Thu, 13 Nov 2008 06:11:30 -0000

Provide a means to add a prefix to the name of the tokens as output in the
generated files.  Because of name clashes, it is good to have such a
prefix such as TOK_ that protects from names such as EOF, FILE etc.
But it clutters the grammar itself.

        * data/bison.m4 (token.prefix): Empty by default.
        * data/c.m4 (b4_token_enum, b4_token_define): Use it.
        * data/lalr1.cc (b4_symbol): Ditto.
---
 ChangeLog     |   12 ++++++++++++
 data/bison.m4 |    7 +++++++
 data/c.m4     |    4 ++--
 data/lalr1.cc |    5 +++--
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 56f3931..b73a85c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-11-13  Akim Demaille  <address@hidden>
 
+       %define token.prefix.
+       Provide a means to add a prefix to the name of the tokens as output in 
the
+       generated files.  Because of name clashes, it is good to have such a
+       prefix such as TOK_ that protects from names such as EOF, FILE etc.
+       But it clutters the grammar itself.
+       
+       * data/bison.m4 (token.prefix): Empty by default.
+       * data/c.m4 (b4_token_enum, b4_token_define): Use it.
+       * data/lalr1.cc (b4_symbol): Ditto.
+
+2008-11-13  Akim Demaille  <address@hidden>
+
        Compute at M4 time some of the subtractions.
        * data/lalr1.cc (b4_substract): New.
        (b4_rhs_data): Use it.
diff --git a/data/bison.m4 b/data/bison.m4
index 31f7818..7cb43b8 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -542,6 +542,13 @@ m4_define([b4_percent_code_ifdef],
          [$3])])
 
 
+# Default values for %define.
+# ---------------------------
+# If the %token.prefix, it is empty.
+m4_percent_define_default([[token.prefix]], [[]])
+
+
+
 ## ----------------------------------------------------------- ##
 ## After processing the skeletons, check that all the user's   ##
 ## %define variables and %code qualifiers were used by Bison.  ##
diff --git a/data/c.m4 b/data/c.m4
index 430a557..6832598 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -159,7 +159,7 @@ m4_define([b4_null], [0])
 # -----------------------------------------
 # Output the definition of this token as #define.
 m4_define([b4_token_define],
-[#define $1 $2
+[#define b4_percent_define_get([token.prefix])$1 $2
 ])
 
 
@@ -177,7 +177,7 @@ m4_map([b4_token_define], address@hidden)])
 # ---------------------------------------
 # Output the definition of this token as an enum.
 m4_define([b4_token_enum],
-[$1 = $2])
+[b4_percent_define_get([token.prefix])$1 = $2])
 
 
 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 97ba371..851c165 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -146,9 +146,10 @@ m4_define([b4_rhs_location],
 # b4_symbol(NUM, FIELD)
 # ---------------------
 # Recover a FIELD about symbol #NUM.  Thanks to m4_indir, fails if
-# undefined.
+# undefined.  If FIELD = id, prepend the prefix.
 m4_define([b4_symbol],
-[m4_indir([b4_symbol($1, $2)])])
+[m4_if([$2], [id], [b4_percent_define_get([token.prefix])])dnl
+m4_indir([b4_symbol($1, $2)])])
 
 
 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
-- 
1.6.0.2.588.g3102





reply via email to

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