* src/symtab.h, src/symtab.c (symbol_t): printer and

printer_location are new members.
(symbol_printer_set): New.
* src/parse-gram.y (PERCENT_PRINTER): New token.
Handle its associated rule.
* src/scan-gram.l: Adjust.
(handle_destructor_at, handle_destructor_dollar): Rename as...
(handle_symbol_code_at, handle_symbol_code_dollar): these.
* src/output.c (symbol_printers_output): New.
(output_skeleton): Call it.
* data/bison.simple (yysymprint): New.  Cannot be named yyprint
since there are already many grammar files with a user `yyprint'.
Replace the calls to YYPRINT to calls to yysymprint.
* tests/calc.at: Adjust.
* tests/torture.at (AT_DATA_STACK_TORTURE): Remove YYPRINT: it was
taking advantage of parser very internal details (stack size!).
This commit is contained in:
Akim Demaille
2002-06-20 09:08:37 +00:00
parent 1ce5149ac8
commit 366eea36d3
13 changed files with 1104 additions and 1011 deletions

View File

@@ -639,6 +639,39 @@ symbol_destructors_output (FILE *out)
}
/*-------------------------------------.
| Output the symbol printers to OOUT. |
`-------------------------------------*/
static void
symbol_printers_output (FILE *out)
{
int i;
int first = 1;
fputs ("m4_define([b4_symbol_printers], \n[", out);
for (i = 0; i < nsyms; ++i)
if (symbols[i]->destructor)
{
symbol_t *symbol = symbols[i];
/* Filename, lineno,
Symbol-name, Symbol-number,
destructor, typename. */
fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
first ? "" : ",\n",
infile, symbol->printer_location.first_line,
symbol_tag_get (symbol),
symbol->number,
symbol->printer,
symbol->type_name);
first = 0;
}
fputs ("])\n\n", out);
}
static void
save_column (int symbol, int default_state)
{
@@ -1053,6 +1086,7 @@ output_skeleton (void)
actions_output (out);
token_definitions_output (out);
symbol_destructors_output (out);
symbol_printers_output (out);
muscles_m4_output (out);

File diff suppressed because it is too large Load Diff

View File

@@ -15,37 +15,38 @@
PERCENT_NTERM = 262,
PERCENT_TYPE = 263,
PERCENT_DESTRUCTOR = 264,
PERCENT_UNION = 265,
PERCENT_LEFT = 266,
PERCENT_RIGHT = 267,
PERCENT_NONASSOC = 268,
PERCENT_EXPECT = 269,
PERCENT_START = 270,
PERCENT_PREC = 271,
PERCENT_VERBOSE = 272,
PERCENT_ERROR_VERBOSE = 273,
PERCENT_OUTPUT = 274,
PERCENT_FILE_PREFIX = 275,
PERCENT_NAME_PREFIX = 276,
PERCENT_DEFINE = 277,
PERCENT_PURE_PARSER = 278,
PERCENT_DEFINES = 279,
PERCENT_YACC = 280,
PERCENT_DEBUG = 281,
PERCENT_LOCATIONS = 282,
PERCENT_NO_LINES = 283,
PERCENT_SKELETON = 284,
PERCENT_TOKEN_TABLE = 285,
TYPE = 286,
EQUAL = 287,
SEMICOLON = 288,
COLON = 289,
PIPE = 290,
ID = 291,
PERCENT_PERCENT = 292,
PROLOGUE = 293,
EPILOGUE = 294,
BRACED_CODE = 295
PERCENT_PRINTER = 265,
PERCENT_UNION = 266,
PERCENT_LEFT = 267,
PERCENT_RIGHT = 268,
PERCENT_NONASSOC = 269,
PERCENT_EXPECT = 270,
PERCENT_START = 271,
PERCENT_PREC = 272,
PERCENT_VERBOSE = 273,
PERCENT_ERROR_VERBOSE = 274,
PERCENT_OUTPUT = 275,
PERCENT_FILE_PREFIX = 276,
PERCENT_NAME_PREFIX = 277,
PERCENT_DEFINE = 278,
PERCENT_PURE_PARSER = 279,
PERCENT_DEFINES = 280,
PERCENT_YACC = 281,
PERCENT_DEBUG = 282,
PERCENT_LOCATIONS = 283,
PERCENT_NO_LINES = 284,
PERCENT_SKELETON = 285,
PERCENT_TOKEN_TABLE = 286,
TYPE = 287,
EQUAL = 288,
SEMICOLON = 289,
COLON = 290,
PIPE = 291,
ID = 292,
PERCENT_PERCENT = 293,
PROLOGUE = 294,
EPILOGUE = 295,
BRACED_CODE = 296
};
# endif
/* POSIX requires `int' for tokens in interfaces. */
@@ -59,37 +60,38 @@
#define PERCENT_NTERM 262
#define PERCENT_TYPE 263
#define PERCENT_DESTRUCTOR 264
#define PERCENT_UNION 265
#define PERCENT_LEFT 266
#define PERCENT_RIGHT 267
#define PERCENT_NONASSOC 268
#define PERCENT_EXPECT 269
#define PERCENT_START 270
#define PERCENT_PREC 271
#define PERCENT_VERBOSE 272
#define PERCENT_ERROR_VERBOSE 273
#define PERCENT_OUTPUT 274
#define PERCENT_FILE_PREFIX 275
#define PERCENT_NAME_PREFIX 276
#define PERCENT_DEFINE 277
#define PERCENT_PURE_PARSER 278
#define PERCENT_DEFINES 279
#define PERCENT_YACC 280
#define PERCENT_DEBUG 281
#define PERCENT_LOCATIONS 282
#define PERCENT_NO_LINES 283
#define PERCENT_SKELETON 284
#define PERCENT_TOKEN_TABLE 285
#define TYPE 286
#define EQUAL 287
#define SEMICOLON 288
#define COLON 289
#define PIPE 290
#define ID 291
#define PERCENT_PERCENT 292
#define PROLOGUE 293
#define EPILOGUE 294
#define BRACED_CODE 295
#define PERCENT_PRINTER 265
#define PERCENT_UNION 266
#define PERCENT_LEFT 267
#define PERCENT_RIGHT 268
#define PERCENT_NONASSOC 269
#define PERCENT_EXPECT 270
#define PERCENT_START 271
#define PERCENT_PREC 272
#define PERCENT_VERBOSE 273
#define PERCENT_ERROR_VERBOSE 274
#define PERCENT_OUTPUT 275
#define PERCENT_FILE_PREFIX 276
#define PERCENT_NAME_PREFIX 277
#define PERCENT_DEFINE 278
#define PERCENT_PURE_PARSER 279
#define PERCENT_DEFINES 280
#define PERCENT_YACC 281
#define PERCENT_DEBUG 282
#define PERCENT_LOCATIONS 283
#define PERCENT_NO_LINES 284
#define PERCENT_SKELETON 285
#define PERCENT_TOKEN_TABLE 286
#define TYPE 287
#define EQUAL 288
#define SEMICOLON 289
#define COLON 290
#define PIPE 291
#define ID 292
#define PERCENT_PERCENT 293
#define PROLOGUE 294
#define EPILOGUE 295
#define BRACED_CODE 296
@@ -103,8 +105,8 @@ typedef union {
char *string;
associativity assoc;
} yystype;
/* Line 1271 of /usr/local/share/bison/bison.simple. */
#line 108 "y.tab.h"
/* Line 1313 of /usr/local/share/bison/bison.simple. */
#line 110 "y.tab.h"
# define YYSTYPE yystype
#endif

View File

@@ -103,9 +103,13 @@ braced_code_t current_braced_code = action_braced_code;
%token PERCENT_TOKEN "%token"
%token PERCENT_NTERM "%nterm"
%token PERCENT_TYPE "%type"
%token PERCENT_DESTRUCTOR "%destructor"
%token PERCENT_PRINTER "%printer"
%token PERCENT_UNION "%union"
%token PERCENT_LEFT "%left"
%token PERCENT_RIGHT "%right"
%token PERCENT_NONASSOC "%nonassoc"
@@ -212,6 +216,16 @@ grammar_declaration:
symbol_list_free ($4);
current_braced_code = action_braced_code;
}
| "%printer"
{ current_braced_code = printer_braced_code; }
BRACED_CODE symbols.1
{
symbol_list_t *list;
for (list = $4; list; list = list->next)
symbol_printer_set (list->sym, $3, list->location);
symbol_list_free ($4);
current_braced_code = action_braced_code;
}
;
symbol_declaration:

View File

@@ -52,7 +52,8 @@ int gram_parse (void *control);
typedef enum braced_code_e
{
action_braced_code,
destructor_braced_code
destructor_braced_code,
printer_braced_code
} braced_code_t;
/* FIXME: This is really a dirty hack which demonstrates that we
should probably not try to parse the actions now. */

File diff suppressed because it is too large Load Diff

View File

@@ -136,6 +136,7 @@ blanks [ \t\f]+
"%nterm" return PERCENT_NTERM;
"%output" return PERCENT_OUTPUT;
"%prec" return PERCENT_PREC;
"%printer" return PERCENT_PRINTER;
"%pure"[-_]"parser" return PERCENT_PURE_PARSER;
"%right" return PERCENT_RIGHT;
"%skeleton" return PERCENT_SKELETON;
@@ -524,7 +525,7 @@ blanks [ \t\f]+
%%
/*------------------------------------------------------------------.
| CP is pointing to a wannabee semantic value (i.e., a `$'). |
| TEXT is pointing to a wannabee semantic value (i.e., a `$'). |
| |
| Possible inputs: $[<TYPENAME>]($|integer) |
| |
@@ -532,11 +533,10 @@ blanks [ \t\f]+
`------------------------------------------------------------------*/
static inline void
handle_action_dollar (char *cp, location_t location)
handle_action_dollar (char *text, location_t location)
{
const char *type_name = NULL;
++cp;
char *cp = text + 1;
/* Get the type name if explicit. */
if (*cp == '<')
@@ -588,31 +588,24 @@ handle_action_dollar (char *cp, location_t location)
}
else
{
char buf[] = "$c";
buf[1] = *cp;
complain_at (location, _("%s is invalid"), quote (buf));
complain_at (location, _("%s is invalid"), quote (text));
}
}
/*---------------------------------------.
| CP is pointing to $$ in a destructor. |
`---------------------------------------*/
/*---------------------------------------------------------------.
| TEXT is expexted tp be $$ in some code associated to a symbol: |
| destructor or printer. |
`---------------------------------------------------------------*/
static inline void
handle_destructor_dollar (char *cp, location_t location)
handle_symbol_code_dollar (char *text, location_t location)
{
++cp;
char *cp = text + 1;
if (*cp == '$')
{
obstack_sgrow (&string_obstack, "]b4_dollar_dollar[");
}
obstack_sgrow (&string_obstack, "]b4_dollar_dollar[");
else
{
char buf[] = "$c";
buf[1] = *cp;
complain_at (location, _("%s is invalid"), quote (buf));
}
complain_at (location, _("%s is invalid"), quote (text));
}
@@ -632,7 +625,8 @@ handle_dollar (braced_code_t braced_code_kind,
break;
case destructor_braced_code:
handle_destructor_dollar (text, location);
case printer_braced_code:
handle_symbol_code_dollar (text, location);
break;
}
}
@@ -646,21 +640,21 @@ handle_dollar (braced_code_t braced_code_kind,
static inline void
handle_action_at (char *text, location_t location)
{
char *cp = text + 1;
locations_flag = 1;
++text;
if (*text == '$')
if (*cp == '$')
{
obstack_sgrow (&string_obstack, "]b4_lhs_location[");
}
else if (isdigit (*text) || *text == '-')
else if (isdigit (*cp) || *cp == '-')
{
/* RULE_LENGTH is the number of values in the current rule so
far, which says where to find `$0' with respect to the top of
the stack. It is not the same as the rule->length in the
case of mid rule actions. */
int rule_length = symbol_list_length (current_rule->next);
int n = strtol (text, &text, 10);
int n = strtol (cp, &cp, 10);
if (n > rule_length)
complain_at (location, _("invalid value: %s%d"), "@", n);
@@ -670,31 +664,24 @@ handle_action_at (char *text, location_t location)
}
else
{
char buf[] = "@c";
buf[1] = *text;
complain_at (location, _("%s is invalid"), quote (buf));
complain_at (location, _("%s is invalid"), quote (text));
}
}
/*--------------------------------------------.
| TEXT is expexted tp be @$ in a destructor. |
`--------------------------------------------*/
/*---------------------------------------------------------------.
| TEXT is expexted tp be @$ in some code associated to a symbol: |
| destructor or printer. |
`---------------------------------------------------------------*/
static inline void
handle_destructor_at (char *text, location_t location)
handle_symbol_code_at (char *text, location_t location)
{
++text;
if (*text == '$')
{
obstack_sgrow (&string_obstack, "]b4_at_dollar[");
}
char *cp = text + 1;
if (*cp == '$')
obstack_sgrow (&string_obstack, "]b4_at_dollar[");
else
{
char buf[] = "$c";
buf[1] = *text;
complain_at (location, _("%s is invalid"), quote (buf));
}
complain_at (location, _("%s is invalid"), quote (text));
}
@@ -714,7 +701,8 @@ handle_at (braced_code_t braced_code_kind,
break;
case destructor_braced_code:
handle_destructor_at (text, location);
case printer_braced_code:
handle_symbol_code_at (text, location);
break;
}
}

View File

@@ -118,8 +118,7 @@ symbol_type_set (symbol_t *symbol, location_t location, char *type_name)
/*-------------------------------------------------------------------.
| Set the DESTRUCTOR associated to SYMBOL. Does nothing if passed 0 |
| as DESTRUCTOR. |
| Set the DESTRUCTOR associated to SYMBOL. Do nothing if passed 0. |
`-------------------------------------------------------------------*/
void
@@ -129,14 +128,33 @@ symbol_destructor_set (symbol_t *symbol, location_t location, char *destructor)
{
if (symbol->destructor)
complain_at (location,
_("destructor redeclaration for %s"),
symbol_tag_get (symbol));
_("%s redeclaration for %s"),
"%destructor", symbol_tag_get (symbol));
symbol->destructor = destructor;
symbol->destructor_location = location;
}
}
/*----------------------------------------------------------------.
| Set the PRITNER associated to SYMBOL. Do nothing if passed 0. |
`----------------------------------------------------------------*/
void
symbol_printer_set (symbol_t *symbol, char *printer, location_t location)
{
if (printer)
{
if (symbol->printer)
complain_at (location,
_("%s redeclaration for %s"),
"%printer", symbol_tag_get (symbol));
symbol->printer = printer;
symbol->printer_location = location;
}
}
/*------------------------------------------------------------------.
| Set the PRECEDENCE associated to SYMBOL. Does nothing if invoked |
| with UNDEF_ASSOC as ASSOC. |

View File

@@ -59,11 +59,12 @@ struct symbol_s
/* The location of its first occurence. */
location_t location;
/* Its %type and associated destructor. */
/* Its %type and associated printer and destructor. */
char *type_name;
char *destructor;
location_t destructor_location;
char *printer;
location_t printer_location;
symbol_number_t number;
short prec;
@@ -116,6 +117,10 @@ void symbol_type_set PARAMS ((symbol_t *symbol, location_t location,
void symbol_destructor_set PARAMS ((symbol_t *symbol, location_t location,
char *destructor));
/* Set the PRINTER associated to SYMBOL. */
void symbol_printer_set PARAMS ((symbol_t *symbol,
char *printer, location_t location));
/* Set the PRECEDENCE associated to SYMBOL. Ensures that SYMBOL is a
terminal. Does nothing if invoked with UNDEF_ASSOC as ASSOC. */
void symbol_precedence_set PARAMS ((symbol_t *symbol, location_t location,