[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: Use %printer
From: |
Akim Demaille |
Subject: |
FYI: Use %printer |
Date: |
Tue, 12 Jul 2005 15:55:42 +0200 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
I'm trying to use the glr parser, but I'm facing problems I don't
understand well... So I go step by step.
Index: ChangeLog
from Akim Demaille <address@hidden>
* src/parse-gram.y: Use %printer instead of YYPRINT.
Index: src/parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.54
diff -u -u -r1.54 parse-gram.y
--- src/parse-gram.y 14 May 2005 06:49:47 -0000 1.54
+++ src/parse-gram.y 12 Jul 2005 13:53:20 -0000
@@ -46,10 +46,6 @@
gram_error (&yylloc, Msg)
static void gram_error (location const *, char const *);
-#define YYPRINT(File, Type, Value) \
- print_token_value (File, Type, &Value)
-static void print_token_value (FILE *, int, YYSTYPE const *);
-
static void add_param (char const *, char *, location);
symbol_class current_class = unknown_sym;
@@ -61,6 +57,7 @@
%}
%debug
+%verbose
%defines
%locations
%pure-parser
@@ -164,9 +161,25 @@
"%union {...}"
BRACED_CODE action
PROLOGUE EPILOGUE
+%printer { fprintf (stderr, "\"%s\"", $$); }
+ STRING string_content
+%printer { fprintf (stderr, "{\n%s\n}", $$); }
+ "%destructor {...}"
+ "%initial-action {...}"
+ "%lex-param {...}"
+ "%parse-param {...}"
+ "%printer {...}"
+ "%union {...}"
+ BRACED_CODE action
+ PROLOGUE EPILOGUE
%type <uniqstr> TYPE
+%printer { fprintf (stderr, "<%s>", $$); } TYPE
%type <integer> INT
-%type <symbol> ID ID_COLON symbol string_as_id
+%printer { fprintf (stderr, "%d", $$); } INT
+%type <symbol> ID symbol string_as_id
+%printer { fprintf (stderr, "%s", $$->tag); } ID symbol string_as_id
+%type <symbol> ID_COLON
+%printer { fprintf (stderr, "%s:", $$->tag); } ID_COLON
%type <assoc> precedence_declarator
%type <list> symbols.1
%%
@@ -514,49 +527,6 @@
}
scanner_last_string_free ();
-}
-
-/*----------------------------------------------------.
-| When debugging the parser, display tokens' values. |
-`----------------------------------------------------*/
-
-static void
-print_token_value (FILE *file, int type, YYSTYPE const *value)
-{
- fputc (' ', file);
- switch (type)
- {
- case ID:
- fprintf (file, " = %s", value->symbol->tag);
- break;
-
- case INT:
- fprintf (file, " = %d", value->integer);
- break;
-
- case STRING:
- fprintf (file, " = \"%s\"", value->chars);
- break;
-
- case TYPE:
- fprintf (file, " = <%s>", value->uniqstr);
- break;
-
- case BRACED_CODE:
- case PERCENT_DESTRUCTOR:
- case PERCENT_LEX_PARAM:
- case PERCENT_PARSE_PARAM:
- case PERCENT_PRINTER:
- case PERCENT_UNION:
- case PROLOGUE:
- case EPILOGUE:
- fprintf (file, " = {{ %s }}", value->chars);
- break;
-
- default:
- fprintf (file, "unknown token type");
- break;
- }
}
static void
- FYI: Use %printer,
Akim Demaille <=