* src/parse-gram.y (YYPRINT, yyprint): Don't mess with the parser

internals.
* src/reader.h, src/reader.c (grammar_current_rule_prec_set):
Takes a location.
* src/symtab.h, src/symtab.c (symbol_class_set)
(symbol_user_token_number_set): Likewise.
Adjust all callers.
Promote complain_at.
* tests/input.at (Type Clashes): Adjust.
This commit is contained in:
Akim Demaille
2002-06-20 11:10:56 +00:00
parent 5c1180b3c4
commit e776192e4f
12 changed files with 213 additions and 204 deletions

View File

@@ -1,3 +1,15 @@
2002-06-20 Akim Demaille <akim@epita.fr>
* src/parse-gram.y (YYPRINT, yyprint): Don't mess with the parser
internals.
* src/reader.h, src/reader.c (grammar_current_rule_prec_set):
Takes a location.
* src/symtab.h, src/symtab.c (symbol_class_set)
(symbol_user_token_number_set): Likewise.
Adjust all callers.
Promote complain_at.
* tests/input.at (Type Clashes): Adjust.
2002-06-20 Akim Demaille <akim@epita.fr> 2002-06-20 Akim Demaille <akim@epita.fr>
* data/bison.simple (YYLEX): Fix the declaration when * data/bison.simple (YYLEX): Fix the declaration when

View File

@@ -100,12 +100,9 @@ do { \
#define yyerror(Msg) \ #define yyerror(Msg) \
gram_error (yycontrol, &yylloc, Msg) gram_error (yycontrol, &yylloc, Msg)
/* When debugging our pure parser, we want to see values and locations
of the tokens. */
#define YYPRINT(File, Type, Value) \ #define YYPRINT(File, Type, Value) \
yyprint (File, &yylloc, Type, &Value) yyprint (File, Type, &Value)
static void yyprint (FILE *file, const location_t *loc, static void yyprint (FILE *file, int type, const yystype *value);
int type, const yystype *value);
symbol_class current_class = unknown_sym; symbol_class current_class = unknown_sym;
char *current_type = 0; char *current_type = 0;
@@ -225,7 +222,7 @@ braced_code_t current_braced_code = action_braced_code;
#endif #endif
#ifndef YYSTYPE #ifndef YYSTYPE
#line 91 "parse-gram.y" #line 88 "parse-gram.y"
typedef union { typedef union {
symbol_t *symbol; symbol_t *symbol;
symbol_list_t *list; symbol_list_t *list;
@@ -234,7 +231,7 @@ typedef union {
associativity assoc; associativity assoc;
} yystype; } yystype;
/* Line 232 of /usr/local/share/bison/bison.simple. */ /* Line 232 of /usr/local/share/bison/bison.simple. */
#line 238 "parse-gram.c" #line 235 "parse-gram.c"
# define YYSTYPE yystype # define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
#endif #endif
@@ -255,7 +252,7 @@ typedef struct yyltype
/* Line 252 of /usr/local/share/bison/bison.simple. */ /* Line 252 of /usr/local/share/bison/bison.simple. */
#line 259 "parse-gram.c" #line 256 "parse-gram.c"
#if ! defined (yyoverflow) || YYERROR_VERBOSE #if ! defined (yyoverflow) || YYERROR_VERBOSE
@@ -444,14 +441,14 @@ static const signed char yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const unsigned short yyrline[] = static const unsigned short yyrline[] =
{ {
0, 158, 158, 171, 173, 176, 178, 179, 180, 181, 0, 155, 155, 168, 170, 173, 175, 176, 177, 178,
182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
192, 193, 196, 198, 199, 203, 210, 209, 220, 219, 189, 190, 193, 195, 196, 200, 207, 206, 217, 216,
232, 231, 237, 237, 242, 251, 266, 268, 269, 272, 229, 228, 234, 234, 239, 248, 263, 265, 266, 269,
274, 279, 281, 285, 290, 295, 301, 307, 317, 320, 271, 276, 278, 282, 287, 292, 298, 304, 314, 317,
329, 331, 337, 339, 343, 342, 347, 349, 352, 355, 326, 328, 334, 336, 340, 339, 344, 346, 349, 352,
357, 359, 363, 365, 366, 369, 375, 384, 392, 397, 354, 356, 360, 362, 363, 366, 372, 381, 389, 394,
403, 405 400, 402
}; };
#endif #endif
@@ -696,7 +693,7 @@ while (0)
#ifdef YYLEX_PARAM #ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
#else #else
# define YYLEX yylex (&yylval, &yylloc, ) # define YYLEX yylex (&yylval, &yylloc)
#endif #endif
/* Enable debugging if requested. */ /* Enable debugging if requested. */
@@ -712,11 +709,17 @@ do { \
if (yydebug) \ if (yydebug) \
YYFPRINTF Args; \ YYFPRINTF Args; \
} while (0) } while (0)
# define YYDSYMPRINT(Args) \
do { \
if (yydebug) \
yysymprint Args; \
} while (0)
/* Nonzero means print parse trace. It is left uninitialized so that /* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */ multiple parsers can coexist. */
int yydebug; int yydebug;
#else /* !YYDEBUG */ #else /* !YYDEBUG */
# define YYDPRINTF(Args) # define YYDPRINTF(Args)
# define YYDSYMPRINT(Args)
#endif /* !YYDEBUG */ #endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */ /* YYINITDEPTH -- initial size of the parser's stacks. */
@@ -823,7 +826,15 @@ int yyparse (void *);
int yyparse (void); int yyparse (void);
# endif # endif
#endif #endif
static void yydestructor (int symbol_type, YYSTYPE symbol_value);
#if defined (__STDC__) || defined (__cplusplus)
static void yydestructor (int yytype,
YYSTYPE yyvalue, YYLTYPE yylocation);
# if YYDEBUG
static void yysymprint (FILE* out, int yytype,
YYSTYPE yyvalue, YYLTYPE yylocation);
# endif
#endif
@@ -1024,21 +1035,11 @@ yybackup:
{ {
yychar1 = YYTRANSLATE (yychar); yychar1 = YYTRANSLATE (yychar);
#if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables
/* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */
which are defined only if `YYDEBUG' is set. */ YYDPRINTF ((stderr, "Next token is "));
if (yydebug) YYDSYMPRINT ((stderr, yychar1, yylval, yyloc));
{ YYDPRINTF ((stderr, "\n"));
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");
}
#endif
} }
yyn += yychar1; yyn += yychar1;
@@ -1136,7 +1137,7 @@ yyreduce:
switch (yyn) switch (yyn)
{ {
case 2: case 2:
#line 160 "parse-gram.y" #line 157 "parse-gram.y"
{ {
yycontrol->errcode = 0; yycontrol->errcode = 0;
epilogue_set (yyvsp[0].string, yylsp[0]); epilogue_set (yyvsp[0].string, yylsp[0]);
@@ -1144,94 +1145,94 @@ yyreduce:
break; break;
case 6: case 6:
#line 178 "parse-gram.y" #line 175 "parse-gram.y"
{ prologue_augment (yyvsp[0].string, yylsp[0]); } { prologue_augment (yyvsp[0].string, yylsp[0]); }
break; break;
case 7: case 7:
#line 179 "parse-gram.y" #line 176 "parse-gram.y"
{ debug_flag = 1; } { debug_flag = 1; }
break; break;
case 8: case 8:
#line 180 "parse-gram.y" #line 177 "parse-gram.y"
{ muscle_insert (yyvsp[-1].string, yyvsp[0].string); } { muscle_insert (yyvsp[-1].string, yyvsp[0].string); }
break; break;
case 9: case 9:
#line 181 "parse-gram.y" #line 178 "parse-gram.y"
{ defines_flag = 1; } { defines_flag = 1; }
break; break;
case 10: case 10:
#line 182 "parse-gram.y" #line 179 "parse-gram.y"
{ error_verbose = 1; } { error_verbose = 1; }
break; break;
case 11: case 11:
#line 183 "parse-gram.y" #line 180 "parse-gram.y"
{ expected_conflicts = yyvsp[0].integer; } { expected_conflicts = yyvsp[0].integer; }
break; break;
case 12: case 12:
#line 184 "parse-gram.y" #line 181 "parse-gram.y"
{ spec_file_prefix = yyvsp[0].string; } { spec_file_prefix = yyvsp[0].string; }
break; break;
case 13: case 13:
#line 185 "parse-gram.y" #line 182 "parse-gram.y"
{ locations_flag = 1; } { locations_flag = 1; }
break; break;
case 14: case 14:
#line 186 "parse-gram.y" #line 183 "parse-gram.y"
{ spec_name_prefix = yyvsp[0].string; } { spec_name_prefix = yyvsp[0].string; }
break; break;
case 15: case 15:
#line 187 "parse-gram.y" #line 184 "parse-gram.y"
{ no_lines_flag = 1; } { no_lines_flag = 1; }
break; break;
case 16: case 16:
#line 188 "parse-gram.y" #line 185 "parse-gram.y"
{ spec_outfile = yyvsp[0].string; } { spec_outfile = yyvsp[0].string; }
break; break;
case 17: case 17:
#line 189 "parse-gram.y" #line 186 "parse-gram.y"
{ pure_parser = 1; } { pure_parser = 1; }
break; break;
case 18: case 18:
#line 190 "parse-gram.y" #line 187 "parse-gram.y"
{ skeleton = yyvsp[0].string; } { skeleton = yyvsp[0].string; }
break; break;
case 19: case 19:
#line 191 "parse-gram.y" #line 188 "parse-gram.y"
{ token_table_flag = 1; } { token_table_flag = 1; }
break; break;
case 20: case 20:
#line 192 "parse-gram.y" #line 189 "parse-gram.y"
{ report_flag = 1; } { report_flag = 1; }
break; break;
case 21: case 21:
#line 193 "parse-gram.y" #line 190 "parse-gram.y"
{ yacc_flag = 1; } { yacc_flag = 1; }
break; break;
case 24: case 24:
#line 200 "parse-gram.y" #line 197 "parse-gram.y"
{ {
grammar_start_symbol_set (yyvsp[0].symbol, yylsp[0]); grammar_start_symbol_set (yyvsp[0].symbol, yylsp[0]);
} }
break; break;
case 25: case 25:
#line 204 "parse-gram.y" #line 201 "parse-gram.y"
{ {
typed = 1; typed = 1;
MUSCLE_INSERT_INT ("stype_line", yylsp[0].first_line); MUSCLE_INSERT_INT ("stype_line", yylsp[0].first_line);
@@ -1240,12 +1241,12 @@ yyreduce:
break; break;
case 26: case 26:
#line 210 "parse-gram.y" #line 207 "parse-gram.y"
{ current_braced_code = destructor_braced_code; } { current_braced_code = destructor_braced_code; }
break; break;
case 27: case 27:
#line 212 "parse-gram.y" #line 209 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
for (list = yyvsp[0].list; list; list = list->next) for (list = yyvsp[0].list; list; list = list->next)
@@ -1256,12 +1257,12 @@ yyreduce:
break; break;
case 28: case 28:
#line 220 "parse-gram.y" #line 217 "parse-gram.y"
{ current_braced_code = printer_braced_code; } { current_braced_code = printer_braced_code; }
break; break;
case 29: case 29:
#line 222 "parse-gram.y" #line 219 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
for (list = yyvsp[0].list; list; list = list->next) for (list = yyvsp[0].list; list; list = list->next)
@@ -1272,12 +1273,12 @@ yyreduce:
break; break;
case 30: case 30:
#line 232 "parse-gram.y" #line 229 "parse-gram.y"
{ current_class = nterm_sym; } { current_class = nterm_sym; }
break; break;
case 31: case 31:
#line 233 "parse-gram.y" #line 230 "parse-gram.y"
{ {
current_class = unknown_sym; current_class = unknown_sym;
current_type = NULL; current_type = NULL;
@@ -1285,12 +1286,12 @@ yyreduce:
break; break;
case 32: case 32:
#line 237 "parse-gram.y" #line 234 "parse-gram.y"
{ current_class = token_sym; } { current_class = token_sym; }
break; break;
case 33: case 33:
#line 238 "parse-gram.y" #line 235 "parse-gram.y"
{ {
current_class = unknown_sym; current_class = unknown_sym;
current_type = NULL; current_type = NULL;
@@ -1298,7 +1299,7 @@ yyreduce:
break; break;
case 34: case 34:
#line 243 "parse-gram.y" #line 240 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
for (list = yyvsp[0].list; list; list = list->next) for (list = yyvsp[0].list; list; list = list->next)
@@ -1308,7 +1309,7 @@ yyreduce:
break; break;
case 35: case 35:
#line 253 "parse-gram.y" #line 250 "parse-gram.y"
{ {
symbol_list_t *list; symbol_list_t *list;
++current_prec; ++current_prec;
@@ -1323,163 +1324,163 @@ yyreduce:
break; break;
case 36: case 36:
#line 267 "parse-gram.y" #line 264 "parse-gram.y"
{ yyval.assoc = left_assoc; } { yyval.assoc = left_assoc; }
break; break;
case 37: case 37:
#line 268 "parse-gram.y" #line 265 "parse-gram.y"
{ yyval.assoc = right_assoc; } { yyval.assoc = right_assoc; }
break; break;
case 38: case 38:
#line 269 "parse-gram.y" #line 266 "parse-gram.y"
{ yyval.assoc = non_assoc; } { yyval.assoc = non_assoc; }
break; break;
case 39: case 39:
#line 273 "parse-gram.y" #line 270 "parse-gram.y"
{ current_type = NULL;} { current_type = NULL;}
break; break;
case 40: case 40:
#line 274 "parse-gram.y" #line 271 "parse-gram.y"
{ current_type = yyvsp[0].string; } { current_type = yyvsp[0].string; }
break; break;
case 41: case 41:
#line 280 "parse-gram.y" #line 277 "parse-gram.y"
{ yyval.list = symbol_list_new (yyvsp[0].symbol, yylsp[0]); } { yyval.list = symbol_list_new (yyvsp[0].symbol, yylsp[0]); }
break; break;
case 42: case 42:
#line 281 "parse-gram.y" #line 278 "parse-gram.y"
{ yyval.list = symbol_list_prepend (yyvsp[-1].list, yyvsp[0].symbol, yylsp[0]); } { yyval.list = symbol_list_prepend (yyvsp[-1].list, yyvsp[0].symbol, yylsp[0]); }
break; break;
case 43: case 43:
#line 287 "parse-gram.y" #line 284 "parse-gram.y"
{ {
current_type = yyvsp[0].string; current_type = yyvsp[0].string;
} }
break; break;
case 44: case 44:
#line 291 "parse-gram.y" #line 288 "parse-gram.y"
{ {
symbol_class_set (yyvsp[0].symbol, current_class); symbol_class_set (yyvsp[0].symbol, current_class, yylsp[0]);
symbol_type_set (yyvsp[0].symbol, yylsp[0], current_type); symbol_type_set (yyvsp[0].symbol, yylsp[0], current_type);
} }
break; break;
case 45: case 45:
#line 296 "parse-gram.y" #line 293 "parse-gram.y"
{ {
symbol_class_set (yyvsp[-1].symbol, current_class); symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]);
symbol_type_set (yyvsp[-1].symbol, yylsp[-1], current_type); symbol_type_set (yyvsp[-1].symbol, yylsp[-1], current_type);
symbol_user_token_number_set (yyvsp[-1].symbol, yyvsp[0].integer); symbol_user_token_number_set (yyvsp[-1].symbol, yyvsp[0].integer, yylsp[0]);
} }
break; break;
case 46: case 46:
#line 302 "parse-gram.y" #line 299 "parse-gram.y"
{ {
symbol_class_set (yyvsp[-1].symbol, current_class); symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]);
symbol_type_set (yyvsp[-1].symbol, yylsp[-1], current_type); symbol_type_set (yyvsp[-1].symbol, yylsp[-1], current_type);
symbol_make_alias (yyvsp[-1].symbol, yyvsp[0].symbol); symbol_make_alias (yyvsp[-1].symbol, yyvsp[0].symbol);
} }
break; break;
case 47: case 47:
#line 308 "parse-gram.y" #line 305 "parse-gram.y"
{ {
symbol_class_set (yyvsp[-2].symbol, current_class); symbol_class_set (yyvsp[-2].symbol, current_class, yylsp[-2]);
symbol_type_set (yyvsp[-2].symbol, yylsp[-2], current_type); symbol_type_set (yyvsp[-2].symbol, yylsp[-2], current_type);
symbol_user_token_number_set (yyvsp[-2].symbol, yyvsp[-1].integer); symbol_user_token_number_set (yyvsp[-2].symbol, yyvsp[-1].integer, yylsp[-1]);
symbol_make_alias (yyvsp[-2].symbol, yyvsp[0].symbol); symbol_make_alias (yyvsp[-2].symbol, yyvsp[0].symbol);
} }
break; break;
case 48: case 48:
#line 319 "parse-gram.y" #line 316 "parse-gram.y"
{;} {;}
break; break;
case 49: case 49:
#line 321 "parse-gram.y" #line 318 "parse-gram.y"
{;} {;}
break; break;
case 54: case 54:
#line 343 "parse-gram.y" #line 340 "parse-gram.y"
{ current_lhs = yyvsp[-1].symbol; current_lhs_location = yylsp[-1]; } { current_lhs = yyvsp[-1].symbol; current_lhs_location = yylsp[-1]; }
break; break;
case 55: case 55:
#line 344 "parse-gram.y" #line 341 "parse-gram.y"
{;} {;}
break; break;
case 56: case 56:
#line 348 "parse-gram.y" #line 345 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); } { grammar_rule_end (yylsp[0]); }
break; break;
case 57: case 57:
#line 349 "parse-gram.y" #line 346 "parse-gram.y"
{ grammar_rule_end (yylsp[0]); } { grammar_rule_end (yylsp[0]); }
break; break;
case 58: case 58:
#line 354 "parse-gram.y" #line 351 "parse-gram.y"
{ grammar_rule_begin (current_lhs, current_lhs_location); } { grammar_rule_begin (current_lhs, current_lhs_location); }
break; break;
case 59: case 59:
#line 356 "parse-gram.y" #line 353 "parse-gram.y"
{ grammar_current_rule_symbol_append (yyvsp[0].symbol, yylsp[0]); } { grammar_current_rule_symbol_append (yyvsp[0].symbol, yylsp[0]); }
break; break;
case 60: case 60:
#line 358 "parse-gram.y" #line 355 "parse-gram.y"
{ grammar_current_rule_action_append (yyvsp[0].string, yylsp[0]); } { grammar_current_rule_action_append (yyvsp[0].string, yylsp[0]); }
break; break;
case 61: case 61:
#line 360 "parse-gram.y" #line 357 "parse-gram.y"
{ grammar_current_rule_prec_set (yyvsp[0].symbol); } { grammar_current_rule_prec_set (yyvsp[0].symbol, yylsp[0]); }
break; break;
case 62: case 62:
#line 364 "parse-gram.y" #line 361 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; } { yyval.symbol = yyvsp[0].symbol; }
break; break;
case 63: case 63:
#line 365 "parse-gram.y" #line 362 "parse-gram.y"
{ yyval.symbol = yyvsp[0].symbol; } { yyval.symbol = yyvsp[0].symbol; }
break; break;
case 64: case 64:
#line 366 "parse-gram.y" #line 363 "parse-gram.y"
{ yyval.symbol = getsym (yyvsp[0].string, yylsp[0]); } { yyval.symbol = getsym (yyvsp[0].string, yylsp[0]); }
break; break;
case 65: case 65:
#line 371 "parse-gram.y" #line 368 "parse-gram.y"
{ yyval.string = yyvsp[0].string; } { yyval.string = yyvsp[0].string; }
break; break;
case 66: case 66:
#line 377 "parse-gram.y" #line 374 "parse-gram.y"
{ {
yyval.symbol = getsym (yyvsp[0].string, yylsp[0]); yyval.symbol = getsym (yyvsp[0].string, yylsp[0]);
symbol_class_set (yyval.symbol, token_sym); symbol_class_set (yyval.symbol, token_sym, yylsp[0]);
} }
break; break;
case 67: case 67:
#line 386 "parse-gram.y" #line 383 "parse-gram.y"
{ {
yyval.string = yyvsp[0].string + 1; yyval.string = yyvsp[0].string + 1;
yyval.string[strlen (yyval.string) - 1] = '\0'; yyval.string[strlen (yyval.string) - 1] = '\0';
@@ -1487,14 +1488,14 @@ yyreduce:
break; break;
case 68: case 68:
#line 394 "parse-gram.y" #line 391 "parse-gram.y"
{ {
yyval.string = xstrdup (""); yyval.string = xstrdup ("");
} }
break; break;
case 69: case 69:
#line 398 "parse-gram.y" #line 395 "parse-gram.y"
{ {
yyval.string = yyvsp[0].string; yyval.string = yyvsp[0].string;
} }
@@ -1503,8 +1504,8 @@ yyreduce:
} }
/* Line 996 of /usr/local/share/bison/bison.simple. */ /* Line 1000 of /usr/local/share/bison/bison.simple. */
#line 1508 "parse-gram.c" #line 1509 "parse-gram.c"
yyvsp -= yylen; yyvsp -= yylen;
yyssp -= yylen; yyssp -= yylen;
@@ -1616,27 +1617,12 @@ yyerrlab1:
/* Pop the rest of the stack. */ /* Pop the rest of the stack. */
while (yyssp > yyss) while (yyssp > yyss)
{ {
#if YYDEBUG YYDPRINTF ((stderr, "Error: popping "));
if (yydebug) YYDSYMPRINT ((stderr,
{ yystos[*yyssp],
if (yystos[*yyssp] < YYNTOKENS) *yyvsp, *yylsp));
{ YYDPRINTF ((stderr, "\n"));
YYFPRINTF (stderr, "Error: popping token %d (%s", yydestructor (yystos[*yyssp], *yyvsp, *yylsp);
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]]);
}
}
#endif
yydestructor (yystos[*yyssp], *yyvsp);
YYPOPSTACK; YYPOPSTACK;
} }
YYABORT; YYABORT;
@@ -1644,7 +1630,7 @@ yyerrlab1:
YYDPRINTF ((stderr, "Discarding token %d (%s).\n", YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
yychar, yytname[yychar1])); yychar, yytname[yychar1]));
yydestructor (yychar1, yylval); yydestructor (yychar1, yylval, yylloc);
yychar = YYEMPTY; yychar = YYEMPTY;
} }
@@ -1671,27 +1657,12 @@ yyerrlab1:
if (yyssp == yyss) if (yyssp == yyss)
YYABORT; YYABORT;
#if YYDEBUG YYDPRINTF ((stderr, "Error: popping "));
if (yydebug) YYDSYMPRINT ((stderr,
{ yystos[*yyssp], *yyvsp, *yylsp));
if (yystos[yystate] < YYNTOKENS) YYDPRINTF ((stderr, "\n"));
{
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]]);
}
}
#endif
yydestructor (yystos[yystate], *yyvsp); yydestructor (yystos[yystate], *yyvsp, *yylsp);
yyvsp--; yyvsp--;
yystate = *--yyssp; yystate = *--yyssp;
yylsp--; yylsp--;
@@ -1753,23 +1724,49 @@ yyreturn:
} }
/*-------------------------------------------------. /*-----------------------------------------------.
| Release the memory associated to SYMBOL-NUMBER. | | Release the memory associated to this symbol. |
`-------------------------------------------------*/ `-----------------------------------------------*/
static void static void
yydestructor (int symbol_type, YYSTYPE symbol_value) yydestructor (int yytype,
YYSTYPE yyvalue, YYLTYPE yylocation)
{ {
switch (symbol_type) switch (yytype)
{ {
default: default:
YYDPRINTF ((stderr, "yydestructor: unknown symbol type: %d (%s)\n",
symbol_type, yytname[symbol_type]));
break; break;
} }
} }
#line 407 "parse-gram.y"
#if YYDEBUG
/*-----------------------------.
| Print this symbol on YYOUT. |
`-----------------------------*/
static void
yysymprint (FILE* yyout, int yytype,
YYSTYPE yyvalue, YYLTYPE yylocation)
{
if (yytype < YYNTOKENS)
YYFPRINTF (yyout, "token %s (", yytname[yytype]);
else
YYFPRINTF (yyout, "nterm %s (", yytname[yytype]);
# ifdef YYPRINT
YYPRINT (yyout, yytype, yyvalue);
# else
switch (yytype)
{
default:
break;
}
# endif /* !defined YYPRINT. */
YYFPRINTF (yyout, ")");
}
#endif /* YYDEBUG. */
#line 404 "parse-gram.y"
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| When debugging the parser, display tokens' locations and values. | | When debugging the parser, display tokens' locations and values. |
@@ -1777,11 +1774,9 @@ yydestructor (int symbol_type, YYSTYPE symbol_value)
static void static void
yyprint (FILE *file, yyprint (FILE *file,
const location_t *loc, int type, const yystype *value) int type, const yystype *value)
{ {
fputs (" (", file); fputc (' ', file);
LOCATION_PRINT (file, *loc);
fputs (")", file);
switch (type) switch (type)
{ {
case CHARACTER: case CHARACTER:

View File

@@ -97,7 +97,7 @@
#ifndef YYSTYPE #ifndef YYSTYPE
#line 91 "parse-gram.y" #line 88 "parse-gram.y"
typedef union { typedef union {
symbol_t *symbol; symbol_t *symbol;
symbol_list_t *list; symbol_list_t *list;
@@ -105,7 +105,7 @@ typedef union {
char *string; char *string;
associativity assoc; associativity assoc;
} yystype; } yystype;
/* Line 1313 of /usr/local/share/bison/bison.simple. */ /* Line 1331 of /usr/local/share/bison/bison.simple. */
#line 110 "y.tab.h" #line 110 "y.tab.h"
# define YYSTYPE yystype # define YYSTYPE yystype
#endif #endif

View File

@@ -69,12 +69,9 @@ do { \
#define yyerror(Msg) \ #define yyerror(Msg) \
gram_error (yycontrol, &yylloc, Msg) gram_error (yycontrol, &yylloc, Msg)
/* When debugging our pure parser, we want to see values and locations
of the tokens. */
#define YYPRINT(File, Type, Value) \ #define YYPRINT(File, Type, Value) \
yyprint (File, &yylloc, Type, &Value) yyprint (File, Type, &Value)
static void yyprint (FILE *file, const location_t *loc, static void yyprint (FILE *file, int type, const yystype *value);
int type, const yystype *value);
symbol_class current_class = unknown_sym; symbol_class current_class = unknown_sym;
char *current_type = 0; char *current_type = 0;
@@ -289,26 +286,26 @@ symbol_def:
} }
| ID | ID
{ {
symbol_class_set ($1, current_class); symbol_class_set ($1, current_class, @1);
symbol_type_set ($1, @1, current_type); symbol_type_set ($1, @1, current_type);
} }
| ID INT | ID INT
{ {
symbol_class_set ($1, current_class); symbol_class_set ($1, current_class, @1);
symbol_type_set ($1, @1, current_type); symbol_type_set ($1, @1, current_type);
symbol_user_token_number_set ($1, $2); symbol_user_token_number_set ($1, $2, @2);
} }
| ID string_as_id | ID string_as_id
{ {
symbol_class_set ($1, current_class); symbol_class_set ($1, current_class, @1);
symbol_type_set ($1, @1, current_type); symbol_type_set ($1, @1, current_type);
symbol_make_alias ($1, $2); symbol_make_alias ($1, $2);
} }
| ID INT string_as_id | ID INT string_as_id
{ {
symbol_class_set ($1, current_class); symbol_class_set ($1, current_class, @1);
symbol_type_set ($1, @1, current_type); symbol_type_set ($1, @1, current_type);
symbol_user_token_number_set ($1, $2); symbol_user_token_number_set ($1, $2, @2);
symbol_make_alias ($1, $3); symbol_make_alias ($1, $3);
} }
; ;
@@ -357,7 +354,7 @@ rhs:
| rhs action | rhs action
{ grammar_current_rule_action_append ($2, @2); } { grammar_current_rule_action_append ($2, @2); }
| rhs "%prec" symbol | rhs "%prec" symbol
{ grammar_current_rule_prec_set ($3); } { grammar_current_rule_prec_set ($3, @3); }
; ;
symbol: symbol:
@@ -376,7 +373,7 @@ string_as_id:
STRING STRING
{ {
$$ = getsym ($1, @1); $$ = getsym ($1, @1);
symbol_class_set ($$, token_sym); symbol_class_set ($$, token_sym, @1);
} }
; ;
@@ -411,11 +408,9 @@ semi_colon.opt:
static void static void
yyprint (FILE *file, yyprint (FILE *file,
const location_t *loc, int type, const yystype *value) int type, const yystype *value)
{ {
fputs (" (", file); fputc (' ', file);
LOCATION_PRINT (file, *loc);
fputs (")", file);
switch (type) switch (type)
{ {
case CHARACTER: case CHARACTER:

View File

@@ -50,7 +50,7 @@ void
grammar_start_symbol_set (symbol_t *s, location_t l) grammar_start_symbol_set (symbol_t *s, location_t l)
{ {
if (start_flag) if (start_flag)
complain (_("multiple %s declarations"), "%start"); complain_at (l, _("multiple %s declarations"), "%start");
else else
{ {
start_flag = 1; start_flag = 1;
@@ -200,7 +200,7 @@ grammar_rule_begin (symbol_t *lhs, location_t location)
++nvars; ++nvars;
} }
else if (lhs->class == token_sym) else if (lhs->class == token_sym)
complain (_("rule given for %s, which is a token"), lhs->tag); complain_at (location, _("rule given for %s, which is a token"), lhs->tag);
} }
/* Check that the last rule (CURRENT_RULE) is properly defined. For /* Check that the last rule (CURRENT_RULE) is properly defined. For
@@ -224,14 +224,16 @@ grammar_current_rule_check (void)
const char *lhs_type = lhs->type_name ? lhs->type_name : ""; const char *lhs_type = lhs->type_name ? lhs->type_name : "";
const char *rhs_type = first_rhs->type_name ? first_rhs->type_name : ""; const char *rhs_type = first_rhs->type_name ? first_rhs->type_name : "";
if (strcmp (lhs_type, rhs_type)) if (strcmp (lhs_type, rhs_type))
complain (_("type clash (`%s' `%s') on default action"), complain_at (current_rule->location,
lhs_type, rhs_type); _("type clash (`%s' `%s') on default action"),
lhs_type, rhs_type);
} }
/* Warn if there is no default for $$ but we need one. */ /* Warn if there is no default for $$ but we need one. */
else else
{ {
if (lhs->type_name) if (lhs->type_name)
complain (_("empty rule for typed nonterminal, and no action")); complain_at (current_rule->location,
_("empty rule for typed nonterminal, and no action"));
} }
} }
@@ -299,10 +301,10 @@ grammar_midrule_action (void)
/* Set the precedence symbol of the current rule to PRECSYM. */ /* Set the precedence symbol of the current rule to PRECSYM. */
void void
grammar_current_rule_prec_set (symbol_t *precsym) grammar_current_rule_prec_set (symbol_t *precsym, location_t location)
{ {
if (current_rule->ruleprec) if (current_rule->ruleprec)
complain (_("two @prec's in a row")); complain_at (location, _("two @prec's in a row"));
current_rule->ruleprec = precsym; current_rule->ruleprec = precsym;
} }

View File

@@ -68,7 +68,8 @@ void grammar_symbol_append PARAMS ((symbol_t *s, location_t l));
void grammar_rule_begin PARAMS ((symbol_t *lhs, location_t l)); void grammar_rule_begin PARAMS ((symbol_t *lhs, location_t l));
void grammar_rule_end PARAMS ((location_t l)); void grammar_rule_end PARAMS ((location_t l));
void grammar_midrule_action PARAMS ((void)); void grammar_midrule_action PARAMS ((void));
void grammar_current_rule_prec_set PARAMS ((symbol_t *precsym)); void grammar_current_rule_prec_set PARAMS ((symbol_t *precsym,
location_t l));
void grammar_current_rule_symbol_append PARAMS ((symbol_t *symbol, void grammar_current_rule_symbol_append PARAMS ((symbol_t *symbol,
location_t l)); location_t l));
void grammar_current_rule_action_append PARAMS ((const char *action, void grammar_current_rule_action_append PARAMS ((const char *action,

View File

@@ -1469,8 +1469,8 @@ YY_RULE_SETUP
{ {
YY_OBS_FINISH; YY_OBS_FINISH;
yylval->symbol = getsym (last_string, *yylloc); yylval->symbol = getsym (last_string, *yylloc);
symbol_class_set (yylval->symbol, token_sym); symbol_class_set (yylval->symbol, token_sym, *yylloc);
symbol_user_token_number_set (yylval->symbol, last_string[1]); symbol_user_token_number_set (yylval->symbol, last_string[1], *yylloc);
YY_OBS_FREE; YY_OBS_FREE;
yy_pop_state (); yy_pop_state ();
return ID; return ID;

View File

@@ -290,8 +290,8 @@ blanks [ \t\f]+
{ {
YY_OBS_FINISH; YY_OBS_FINISH;
yylval->symbol = getsym (last_string, *yylloc); yylval->symbol = getsym (last_string, *yylloc);
symbol_class_set (yylval->symbol, token_sym); symbol_class_set (yylval->symbol, token_sym, *yylloc);
symbol_user_token_number_set (yylval->symbol, last_string[1]); symbol_user_token_number_set (yylval->symbol, last_string[1], *yylloc);
YY_OBS_FREE; YY_OBS_FREE;
yy_pop_state (); yy_pop_state ();
return ID; return ID;

View File

@@ -175,7 +175,7 @@ symbol_precedence_set (symbol_t *symbol, location_t location,
} }
/* Only terminals have a precedence. */ /* Only terminals have a precedence. */
symbol_class_set (symbol, token_sym); symbol_class_set (symbol, token_sym, location);
} }
@@ -184,10 +184,10 @@ symbol_precedence_set (symbol_t *symbol, location_t location,
`-------------------------------------*/ `-------------------------------------*/
void void
symbol_class_set (symbol_t *symbol, symbol_class class) symbol_class_set (symbol_t *symbol, symbol_class class, location_t location)
{ {
if (symbol->class != unknown_sym && symbol->class != class) if (symbol->class != unknown_sym && symbol->class != class)
complain (_("symbol %s redefined"), symbol_tag_get (symbol)); complain_at (location, _("symbol %s redefined"), symbol_tag_get (symbol));
if (class == nterm_sym && symbol->class != nterm_sym) if (class == nterm_sym && symbol->class != nterm_sym)
symbol->number = nvars++; symbol->number = nvars++;
@@ -203,14 +203,15 @@ symbol_class_set (symbol_t *symbol, symbol_class class)
`-------------------------------------------------*/ `-------------------------------------------------*/
void void
symbol_user_token_number_set (symbol_t *symbol, int user_token_number) symbol_user_token_number_set (symbol_t *symbol,
int user_token_number, location_t location)
{ {
assert (symbol->class == token_sym); assert (symbol->class == token_sym);
if (symbol->user_token_number != USER_NUMBER_UNDEFINED if (symbol->user_token_number != USER_NUMBER_UNDEFINED
&& symbol->user_token_number != user_token_number) && symbol->user_token_number != user_token_number)
complain (_("redefining user token number of %s"), complain_at (location, _("redefining user token number of %s"),
symbol_tag_get (symbol)); symbol_tag_get (symbol));
symbol->user_token_number = user_token_number; symbol->user_token_number = user_token_number;
/* User defined EOF token? */ /* User defined EOF token? */

View File

@@ -127,10 +127,13 @@ void symbol_precedence_set PARAMS ((symbol_t *symbol, location_t location,
int prec, associativity assoc)); int prec, associativity assoc));
/* Set the CLASS associated to SYMBOL. */ /* Set the CLASS associated to SYMBOL. */
void symbol_class_set PARAMS ((symbol_t *symbol, symbol_class class)); void symbol_class_set PARAMS ((symbol_t *symbol,
symbol_class class, location_t location));
/* Set the USER_TOKEN_NUMBER associated to SYMBOL. */ /* Set the USER_TOKEN_NUMBER associated to SYMBOL. */
void symbol_user_token_number_set PARAMS ((symbol_t *symbol, int user_number)); void symbol_user_token_number_set PARAMS ((symbol_t *symbol,
int user_number,
location_t location));
/* Distinguished symbols. AXIOM is the real start symbol, that used /* Distinguished symbols. AXIOM is the real start symbol, that used

View File

@@ -153,11 +153,11 @@ AT_CLEANUP
## ------------- ## ## -------------------------- ##
## Destructors. ## ## Printers and Destructors. ##
## ------------- ## ## -------------------------- ##
AT_SETUP([Destructors]) AT_SETUP([Printers and Destructors])
# Make sure complex $n work. # Make sure complex $n work.

View File

@@ -82,10 +82,10 @@ AT_CLEANUP
## -------------- ## ## -------------- ##
## Type clashes. ## ## Type Clashes. ##
## -------------- ## ## -------------- ##
AT_SETUP([Type clashes]) AT_SETUP([Type Clashes])
AT_DATA([input.y], AT_DATA([input.y],
[[%token foo [[%token foo
@@ -98,9 +98,9 @@ exp: foo {} foo
]]) ]])
AT_CHECK([bison input.y], [1], [], AT_CHECK([bison input.y], [1], [],
[[input.y:5: type clash (`bar' `') on default action [[input.y:4.4-15: type clash (`bar' `') on default action
input.y:6: type clash (`bar' `') on default action input.y:5.4-8: type clash (`bar' `') on default action
input.y:7: empty rule for typed nonterminal, and no action input.y:6.4: empty rule for typed nonterminal, and no action
]]) ]])
AT_CLEANUP AT_CLEANUP