[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: %union ... {
From: |
Paul Eggert |
Subject: |
Re: %union ... { |
Date: |
Mon, 19 Jun 2006 14:42:00 -0700 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
Akim Demaille <address@hidden> writes:
> (ID, ID_COLON): Now that the scanner no longer makes them
> identifiers, adjust all uses to invoke symbol_get.
Thanks.
Doesn't this invoke uniqstr_new on the same symbol twice? Once by the
scanner, and once by the parser. Admittedly hashing is not the
biggest overhead in Bison, but still it's a bit weird that we
immediately look up the same symbol twice in the same table.
Also, it appears to me that the error messages won't quote chars
(or, now that I see it, strings) correctly if they contain control
chars. This one is easy; I installed the following patch.
2006-06-19 Paul Eggert <address@hidden>
* src/parse-gram.y (char_name): New function.
(CHAR, STRING, string_content): For %printer, properly escape.
(ID): Prefer fputs to fprintf.
(id): Reindent to be consistent with other rules.
Properly quote char.
--- src/parse-gram.y 19 Jun 2006 16:49:44 -0000 1.76
+++ src/parse-gram.y 19 Jun 2006 21:32:40 -0000 1.77
@@ -51,6 +51,8 @@ static void version_check (location cons
gram_error (&yylloc, Msg)
static void gram_error (location const *, char const *);
+static char const *char_name (char);
+
static void add_param (char const *, char *, location);
static symbol_class current_class = unknown_sym;
@@ -169,15 +171,16 @@ static int current_prec = 0;
%token TYPE "type"
%type <character> CHAR
-%printer { fprintf (stderr, "'%c' (%d)", $$, $$); } CHAR
+%printer { fputs (char_name ($$), stderr); } CHAR
%type <chars> STRING string_content "{...}" PROLOGUE EPILOGUE
-%printer { fprintf (stderr, "\"%s\"", $$); } STRING string_content
+%printer { fputs (quotearg_style (c_quoting_style, $$), stderr); }
+ STRING string_content
%printer { fprintf (stderr, "{\n%s\n}", $$); } "{...}" PROLOGUE EPILOGUE
%type <uniqstr> TYPE ID ID_COLON
%printer { fprintf (stderr, "<%s>", $$); } TYPE
-%printer { fprintf (stderr, "%s", $$); } ID
+%printer { fputs ($$, stderr); } ID
%printer { fprintf (stderr, "%s:", $$); } ID_COLON
%type <integer> INT
@@ -455,17 +458,18 @@ rhs:
| Identifiers. |
*---------------*/
-/* Identifiers are return as uniqstr by the scanner. Depending on
- their use, we may need to make them genuine symbols. */
+/* Identifiers are returned as uniqstr values by the scanner.
+ Depending on their use, we may need to make them genuine symbols. */
id:
- ID { $$ = symbol_get ($1, @1); }
-| CHAR { char cp[4] = { '\'', $1, '\'', 0 };
- $$ = symbol_get (quotearg_style (escape_quoting_style, cp),
- @1);
- symbol_class_set ($$, token_sym, @1, false);
- symbol_user_token_number_set ($$, $1, @1);
- }
+ ID
+ { $$ = symbol_get ($1, @1); }
+| CHAR
+ {
+ $$ = symbol_get (char_name ($1), @1);
+ symbol_class_set ($$, token_sym, @1, false);
+ symbol_user_token_number_set ($$, $1, @1);
+ }
;
id_colon:
@@ -609,3 +613,16 @@ token_name (int type)
{
return yytname[YYTRANSLATE (type)];
}
+
+static char const *
+char_name (char c)
+{
+ if (c == '\'')
+ return "'\\''";
+ else
+ {
+ char buf[4];
+ buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
+ return quotearg_style (escape_quoting_style, buf);
+ }
+}
- Re: Dubious features, (continued)
- Re: Dubious features, Akim Demaille, 2006/06/08
- Re: Dubious features, Paul Eggert, 2006/06/08
- Re: Dubious features, Akim Demaille, 2006/06/10
- Re: Dubious features, Paul Eggert, 2006/06/11
- Re: %union ... {, Akim Demaille, 2006/06/16
- Re: %union ... {, Paul Eggert, 2006/06/16
- Re: %union ... {, Akim Demaille, 2006/06/17
- Re: %union ... {, Paul Eggert, 2006/06/19
- Re: %union ... {, Hans Aberg, 2006/06/19
- Re: %union ... {, Akim Demaille, 2006/06/19
- Re: %union ... {,
Paul Eggert <=
- Re: %union ... {, Akim Demaille, 2006/06/20
- Problems with CVS, Akim Demaille, 2006/06/20
- Re: Problems with CVS, Paul Eggert, 2006/06/20
- Re: %union ... {, Joel E. Denny, 2006/06/19
- Re: %union ... {, Akim Demaille, 2006/06/20
- Re: %union ... {, Hans Aberg, 2006/06/20