mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
* 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:
20
ChangeLog
20
ChangeLog
@@ -1,10 +1,28 @@
|
||||
2002-06-20 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* 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!).
|
||||
|
||||
2002-06-20 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/scan-gram.l: Complete the scanner with the missing patterns
|
||||
to pacify Flex.
|
||||
Use `quote' and `symbol_tag_get' where appropriate.
|
||||
|
||||
|
||||
2002-06-19 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* tests/actions.at (Destructors): Augment to test locations.
|
||||
|
||||
@@ -671,6 +671,10 @@ int yyparse (void);
|
||||
#if defined (__STDC__) || defined (__cplusplus)
|
||||
static void yydestructor (int yytype,
|
||||
YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
|
||||
# if YYDEBUG
|
||||
static void yysymprint (FILE* out, int yytype,
|
||||
YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
|
||||
# endif
|
||||
#endif
|
||||
|
||||
m4_divert_push([KILL])# ======================== M4 code.
|
||||
@@ -887,14 +891,9 @@ yybackup:
|
||||
which are defined only if `YYDEBUG' is set. */
|
||||
if (yydebug)
|
||||
{
|
||||
YYFPRINTF (stderr, "Next token is %d (%s",
|
||||
yychar, yytname[yychar1]);
|
||||
/* Give the individual parser a way to print the precise
|
||||
meaning of a token, for further debugging info. */
|
||||
# ifdef YYPRINT
|
||||
YYPRINT (stderr, yychar, yylval);
|
||||
# endif
|
||||
YYFPRINTF (stderr, ")\n");
|
||||
YYFPRINTF (stderr, "Next token is ");
|
||||
yysymprint (stderr, yychar1, yylval]b4_location_if([, yyloc])[);
|
||||
YYFPRINTF (stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1113,21 +1112,11 @@ yyerrlab1:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
if (yystos[*yyssp] < YYNTOKENS)
|
||||
{
|
||||
YYFPRINTF (stderr, "Error: popping token %d (%s",
|
||||
yytoknum[yystos[*yyssp]],
|
||||
yytname[yystos[*yyssp]]);
|
||||
# ifdef YYPRINT
|
||||
YYPRINT (stderr, yytoknum[yystos[*yyssp]], *yyvsp);
|
||||
# endif
|
||||
YYFPRINTF (stderr, ")\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n",
|
||||
yytname[yystos[*yyssp]]);
|
||||
}
|
||||
YYFPRINTF (stderr, "Error: popping ");
|
||||
yysymprint (stderr,
|
||||
yystos[*yyssp],
|
||||
*yyvsp]b4_location_if([, *yylsp])[);
|
||||
YYFPRINTF (stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
yydestructor (yystos[*yyssp], *yyvsp]b4_location_if([, *yylsp])[);
|
||||
@@ -1168,20 +1157,11 @@ yyerrlab1:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
if (yystos[yystate] < YYNTOKENS)
|
||||
{
|
||||
YYFPRINTF (stderr, "Error: popping token %d (%s",
|
||||
yytoknum[yystos[yystate]], yytname[yystos[yystate]]);
|
||||
# ifdef YYPRINT
|
||||
YYPRINT (stderr, yytoknum[yystos[yystate]], *yyvsp);
|
||||
# endif
|
||||
YYFPRINTF (stderr, ")\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n",
|
||||
yytname[yystos[yystate]]);
|
||||
}
|
||||
YYFPRINTF (stderr, "Error: popping ");
|
||||
yysymprint (stderr,
|
||||
yystos[*yyssp],
|
||||
*yyvsp]b4_location_if([, *yylsp])[);
|
||||
YYFPRINTF (stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1247,9 +1227,9 @@ yyreturn:
|
||||
]}
|
||||
|
||||
|
||||
/*-------------------------------------------------.
|
||||
| Release the memory associated to SYMBOL-NUMBER. |
|
||||
`-------------------------------------------------*/
|
||||
/*-----------------------------------------------.
|
||||
| Release the memory associated to this symbol. |
|
||||
`-----------------------------------------------*/
|
||||
|
||||
m4_divert_push([KILL])# M4 code.
|
||||
# b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME)
|
||||
@@ -1274,12 +1254,53 @@ yydestructor (int yytype,
|
||||
{
|
||||
m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl
|
||||
default:
|
||||
YYDPRINTF ((stderr, "yydestructor: unknown symbol type: %d (%s)\n",
|
||||
yytype, yytname[[yytype]]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if YYDEBUG
|
||||
/*---------------------------.
|
||||
| Print this symbol on OUT. |
|
||||
`---------------------------*/
|
||||
|
||||
m4_divert_push([KILL])# M4 code.
|
||||
# b4_symbol_printer(SYMBOL-NUMBER, PRINTER, TYPE-NAME)
|
||||
# ----------------------------------------------------------
|
||||
m4_define([b4_symbol_printer],
|
||||
[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
|
||||
m4_pushdef([b4_at_dollar], [yylocation])dnl
|
||||
case $4: /* $3 */
|
||||
#line $2 "$1"
|
||||
$5;
|
||||
#line __oline__ "__ofile__"
|
||||
break;
|
||||
m4_popdef([b4_at_dollar])dnl
|
||||
m4_popdef([b4_dollar_dollar])])
|
||||
|
||||
m4_divert_pop([KILL])dnl# End of M4 code.
|
||||
static void
|
||||
yysymprint (FILE* out, int yytype,
|
||||
YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]))
|
||||
{
|
||||
if (yytype < YYNTOKENS)
|
||||
YYFPRINTF (out, "token %d (%s ", yytoknum[[yytype]], yytname[[yytype]]);
|
||||
else
|
||||
YYFPRINTF (out, "nterm %s (", yytname[[yytype]]);
|
||||
# ifdef YYPRINT
|
||||
YYPRINT (out, yytype, yyvalue);
|
||||
# else
|
||||
switch (yytype)
|
||||
{
|
||||
m4_map([b4_symbol_printer], m4_defn([b4_symbol_printers]))dnl
|
||||
default:
|
||||
break;
|
||||
}
|
||||
# endif /* !defined YYPRINT. */
|
||||
YYFPRINTF (out, ")");
|
||||
}
|
||||
#endif /* YYDEBUG. */
|
||||
|
||||
b4_epilogue
|
||||
m4_if(b4_defines_flag, 0, [],
|
||||
[#output "b4_output_header_name"
|
||||
|
||||
34
src/output.c
34
src/output.c
@@ -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);
|
||||
|
||||
|
||||
797
src/parse-gram.c
797
src/parse-gram.c
File diff suppressed because it is too large
Load Diff
130
src/parse-gram.h
130
src/parse-gram.h
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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. */
|
||||
|
||||
880
src/scan-gram.c
880
src/scan-gram.c
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
26
src/symtab.c
26
src/symtab.c
@@ -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. |
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -415,40 +415,34 @@ _AT_CHECK_CALC([$1],
|
||||
(2^2)^3 = 64], [486])
|
||||
|
||||
# Some parse errors.
|
||||
_AT_CHECK_CALC_ERROR([$1], [0 0], [12],
|
||||
_AT_CHECK_CALC_ERROR([$1], [0 0], [11],
|
||||
[1.3-1.4: parse error, unexpected "number"])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1//2], [17],
|
||||
_AT_CHECK_CALC_ERROR([$1], [1//2], [15],
|
||||
[1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '('])
|
||||
_AT_CHECK_CALC_ERROR([$1], [error], [4],
|
||||
[1.1-1.2: parse error, unexpected $undefined., expecting "number" or '-' or '\n' or '('])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [25],
|
||||
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22],
|
||||
[1.7-1.8: parse error, unexpected '='])
|
||||
_AT_CHECK_CALC_ERROR([$1],
|
||||
[
|
||||
+1],
|
||||
[15],
|
||||
[14],
|
||||
[2.1-2.2: parse error, unexpected '+'])
|
||||
# Exercise error messages with EOF: work on an empty file.
|
||||
_AT_CHECK_CALC_ERROR([$1],
|
||||
[/dev/null],
|
||||
[4],
|
||||
_AT_CHECK_CALC_ERROR([$1], [/dev/null], [4],
|
||||
[1.1-1.2: parse error, unexpected "end of file", expecting "number" or '-' or '\n' or '('])
|
||||
|
||||
# Exercise the error token: without it, we die at the first error,
|
||||
# hence be sure i. to have several errors, ii. to test the action
|
||||
# associated to `error'.
|
||||
_AT_CHECK_CALC_ERROR([$1],
|
||||
[(1 ++ 2) + (0 0) = 1],
|
||||
[91],
|
||||
_AT_CHECK_CALC_ERROR([$1], [(1 ++ 2) + (0 0) = 1], [82],
|
||||
[1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '('
|
||||
1.15-1.16: parse error, unexpected "number"
|
||||
calc: error: 0 != 1])
|
||||
|
||||
# Add a studid example demonstrating that Bison can further improve the
|
||||
# error message. FIXME: Fix this ridiculous message.
|
||||
_AT_CHECK_CALC_ERROR([$1],
|
||||
[()],
|
||||
[21],
|
||||
_AT_CHECK_CALC_ERROR([$1], [()], [21],
|
||||
[1.2-1.3: parse error, unexpected ')', expecting error or "number" or '-' or '('])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -371,9 +371,6 @@ AT_DATA([input.y],
|
||||
]$1[
|
||||
static int yylex (void);
|
||||
static void yyerror (const char *msg);
|
||||
#define YYPRINT(File, Type, Value) \
|
||||
fprintf (File, " (%d, stack size = %d, max = %d)", \
|
||||
Value, yyssp - yyss + 1, yystacksize);
|
||||
%}
|
||||
%error-verbose
|
||||
%debug
|
||||
|
||||
Reference in New Issue
Block a user