mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
* src/reader.h, src/reader.c (symbol_list, symbol_list_new)
(symbol_list_prepend, get_type_name): Move to... * src/symlist.h, src/symlist.c (symbol_list_t, symbol_list_new) (symbol_list_prepend, symbol_list_n_type_name_get): here. Adjust all callers. (symbol_list_free): New. * src/scan-gram.l (handle_dollar): Takes a location. * tests/input.at (Invalid $n): Adjust.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
||||
2002-06-17 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/reader.h, src/reader.c (symbol_list, symbol_list_new)
|
||||
(symbol_list_prepend, get_type_name): Move to...
|
||||
* src/symlist.h, src/symlist.c (symbol_list_t, symbol_list_new)
|
||||
(symbol_list_prepend, symbol_list_n_type_name_get): here.
|
||||
Adjust all callers.
|
||||
(symbol_list_free): New.
|
||||
* src/scan-gram.l (handle_dollar): Takes a location.
|
||||
* tests/input.at (Invalid $n): Adjust.
|
||||
|
||||
|
||||
2002-06-17 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/reader.h, src/reader.c (symbol_list_new): Export it.
|
||||
|
||||
@@ -59,6 +59,7 @@ bison_SOURCES = \
|
||||
scan-gram.l \
|
||||
scan-skel.l \
|
||||
state.c state.h \
|
||||
symlist.c symlist.h \
|
||||
symtab.c symtab.h \
|
||||
system.h \
|
||||
types.h \
|
||||
|
||||
157
src/parse-gram.c
157
src/parse-gram.c
@@ -68,6 +68,7 @@
|
||||
#include "files.h"
|
||||
#include "getargs.h"
|
||||
#include "output.h"
|
||||
#include "symlist.h"
|
||||
#include "gram.h"
|
||||
#include "reader.h"
|
||||
#include "conflicts.h"
|
||||
@@ -222,16 +223,16 @@ int current_prec = 0;
|
||||
#endif
|
||||
|
||||
#ifndef YYSTYPE
|
||||
#line 89 "parse-gram.y"
|
||||
#line 90 "parse-gram.y"
|
||||
typedef union {
|
||||
symbol_t *symbol;
|
||||
symbol_list *list;
|
||||
symbol_list_t *list;
|
||||
int integer;
|
||||
char *string;
|
||||
associativity assoc;
|
||||
} yystype;
|
||||
/* Line 199 of /usr/local/share/bison/bison.simple. */
|
||||
#line 235 "parse-gram.c"
|
||||
#line 236 "parse-gram.c"
|
||||
# define YYSTYPE yystype
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
@@ -252,7 +253,7 @@ typedef struct yyltype
|
||||
|
||||
|
||||
/* Line 219 of /usr/local/share/bison/bison.simple. */
|
||||
#line 256 "parse-gram.c"
|
||||
#line 257 "parse-gram.c"
|
||||
|
||||
#if ! defined (yyoverflow) || YYERROR_VERBOSE
|
||||
|
||||
@@ -447,13 +448,13 @@ static const signed char yyrhs[] =
|
||||
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
|
||||
static const unsigned short yyrline[] =
|
||||
{
|
||||
0, 151, 151, 164, 166, 169, 171, 172, 173, 174,
|
||||
175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
|
||||
185, 186, 189, 191, 192, 196, 204, 204, 210, 210,
|
||||
215, 224, 239, 241, 242, 245, 247, 252, 254, 258,
|
||||
263, 268, 274, 280, 290, 293, 302, 304, 310, 312,
|
||||
315, 315, 320, 322, 325, 328, 330, 332, 336, 338,
|
||||
339, 342, 348, 357, 365, 370, 376, 378
|
||||
0, 152, 152, 165, 167, 170, 172, 173, 174, 175,
|
||||
176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
|
||||
186, 187, 190, 192, 193, 197, 205, 205, 211, 211,
|
||||
216, 225, 240, 242, 243, 246, 248, 253, 255, 259,
|
||||
264, 269, 275, 281, 291, 294, 303, 305, 311, 313,
|
||||
316, 316, 321, 323, 326, 329, 331, 333, 337, 339,
|
||||
340, 343, 349, 358, 366, 371, 377, 379
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1183,7 +1184,7 @@ yyreduce:
|
||||
switch (yyn)
|
||||
{
|
||||
case 2:
|
||||
#line 153 "parse-gram.y"
|
||||
#line 154 "parse-gram.y"
|
||||
{
|
||||
yycontrol->errcode = 0;
|
||||
epilogue_set (yyvsp[0].string, yylsp[0]);
|
||||
@@ -1191,94 +1192,94 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 6:
|
||||
#line 171 "parse-gram.y"
|
||||
#line 172 "parse-gram.y"
|
||||
{ prologue_augment (yyvsp[0].string, yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 7:
|
||||
#line 172 "parse-gram.y"
|
||||
#line 173 "parse-gram.y"
|
||||
{ debug_flag = 1; }
|
||||
break;
|
||||
|
||||
case 8:
|
||||
#line 173 "parse-gram.y"
|
||||
#line 174 "parse-gram.y"
|
||||
{ muscle_insert (yyvsp[-1].string, yyvsp[0].string); }
|
||||
break;
|
||||
|
||||
case 9:
|
||||
#line 174 "parse-gram.y"
|
||||
#line 175 "parse-gram.y"
|
||||
{ defines_flag = 1; }
|
||||
break;
|
||||
|
||||
case 10:
|
||||
#line 175 "parse-gram.y"
|
||||
#line 176 "parse-gram.y"
|
||||
{ error_verbose = 1; }
|
||||
break;
|
||||
|
||||
case 11:
|
||||
#line 176 "parse-gram.y"
|
||||
#line 177 "parse-gram.y"
|
||||
{ expected_conflicts = yyvsp[0].integer; }
|
||||
break;
|
||||
|
||||
case 12:
|
||||
#line 177 "parse-gram.y"
|
||||
#line 178 "parse-gram.y"
|
||||
{ spec_file_prefix = yyvsp[0].string; }
|
||||
break;
|
||||
|
||||
case 13:
|
||||
#line 178 "parse-gram.y"
|
||||
#line 179 "parse-gram.y"
|
||||
{ locations_flag = 1; }
|
||||
break;
|
||||
|
||||
case 14:
|
||||
#line 179 "parse-gram.y"
|
||||
#line 180 "parse-gram.y"
|
||||
{ spec_name_prefix = yyvsp[0].string; }
|
||||
break;
|
||||
|
||||
case 15:
|
||||
#line 180 "parse-gram.y"
|
||||
#line 181 "parse-gram.y"
|
||||
{ no_lines_flag = 1; }
|
||||
break;
|
||||
|
||||
case 16:
|
||||
#line 181 "parse-gram.y"
|
||||
#line 182 "parse-gram.y"
|
||||
{ spec_outfile = yyvsp[0].string; }
|
||||
break;
|
||||
|
||||
case 17:
|
||||
#line 182 "parse-gram.y"
|
||||
#line 183 "parse-gram.y"
|
||||
{ pure_parser = 1; }
|
||||
break;
|
||||
|
||||
case 18:
|
||||
#line 183 "parse-gram.y"
|
||||
#line 184 "parse-gram.y"
|
||||
{ skeleton = yyvsp[0].string; }
|
||||
break;
|
||||
|
||||
case 19:
|
||||
#line 184 "parse-gram.y"
|
||||
#line 185 "parse-gram.y"
|
||||
{ token_table_flag = 1; }
|
||||
break;
|
||||
|
||||
case 20:
|
||||
#line 185 "parse-gram.y"
|
||||
#line 186 "parse-gram.y"
|
||||
{ report_flag = 1; }
|
||||
break;
|
||||
|
||||
case 21:
|
||||
#line 186 "parse-gram.y"
|
||||
#line 187 "parse-gram.y"
|
||||
{ yacc_flag = 1; }
|
||||
break;
|
||||
|
||||
case 24:
|
||||
#line 193 "parse-gram.y"
|
||||
#line 194 "parse-gram.y"
|
||||
{
|
||||
grammar_start_symbol_set (yyvsp[0].symbol, yylsp[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 25:
|
||||
#line 197 "parse-gram.y"
|
||||
#line 198 "parse-gram.y"
|
||||
{
|
||||
typed = 1;
|
||||
MUSCLE_INSERT_INT ("stype_line", yylsp[0].first_line);
|
||||
@@ -1287,12 +1288,12 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 26:
|
||||
#line 205 "parse-gram.y"
|
||||
#line 206 "parse-gram.y"
|
||||
{ current_class = nterm_sym; }
|
||||
break;
|
||||
|
||||
case 27:
|
||||
#line 206 "parse-gram.y"
|
||||
#line 207 "parse-gram.y"
|
||||
{
|
||||
current_class = unknown_sym;
|
||||
current_type = NULL;
|
||||
@@ -1300,12 +1301,12 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 28:
|
||||
#line 210 "parse-gram.y"
|
||||
#line 211 "parse-gram.y"
|
||||
{ current_class = token_sym; }
|
||||
break;
|
||||
|
||||
case 29:
|
||||
#line 211 "parse-gram.y"
|
||||
#line 212 "parse-gram.y"
|
||||
{
|
||||
current_class = unknown_sym;
|
||||
current_type = NULL;
|
||||
@@ -1313,74 +1314,74 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 30:
|
||||
#line 216 "parse-gram.y"
|
||||
#line 217 "parse-gram.y"
|
||||
{
|
||||
symbol_list *list;
|
||||
symbol_list_t *list;
|
||||
for (list = yyvsp[0].list; list; list = list->next)
|
||||
symbol_type_set (list->sym, list->location, yyvsp[-1].string);
|
||||
LIST_FREE (symbol_list, yyvsp[0].list);
|
||||
LIST_FREE (symbol_list_t, yyvsp[0].list);
|
||||
}
|
||||
break;
|
||||
|
||||
case 31:
|
||||
#line 226 "parse-gram.y"
|
||||
#line 227 "parse-gram.y"
|
||||
{
|
||||
symbol_list *list;
|
||||
symbol_list_t *list;
|
||||
++current_prec;
|
||||
for (list = yyvsp[0].list; list; list = list->next)
|
||||
{
|
||||
symbol_type_set (list->sym, list->location, current_type);
|
||||
symbol_precedence_set (list->sym, list->location, current_prec, yyvsp[-2].assoc);
|
||||
}
|
||||
LIST_FREE (symbol_list, yyvsp[0].list);
|
||||
LIST_FREE (symbol_list_t, yyvsp[0].list);
|
||||
current_type = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case 32:
|
||||
#line 240 "parse-gram.y"
|
||||
#line 241 "parse-gram.y"
|
||||
{ yyval.assoc = left_assoc; }
|
||||
break;
|
||||
|
||||
case 33:
|
||||
#line 241 "parse-gram.y"
|
||||
#line 242 "parse-gram.y"
|
||||
{ yyval.assoc = right_assoc; }
|
||||
break;
|
||||
|
||||
case 34:
|
||||
#line 242 "parse-gram.y"
|
||||
#line 243 "parse-gram.y"
|
||||
{ yyval.assoc = non_assoc; }
|
||||
break;
|
||||
|
||||
case 35:
|
||||
#line 246 "parse-gram.y"
|
||||
#line 247 "parse-gram.y"
|
||||
{ current_type = NULL;}
|
||||
break;
|
||||
|
||||
case 36:
|
||||
#line 247 "parse-gram.y"
|
||||
#line 248 "parse-gram.y"
|
||||
{ current_type = yyvsp[0].string; }
|
||||
break;
|
||||
|
||||
case 37:
|
||||
#line 253 "parse-gram.y"
|
||||
#line 254 "parse-gram.y"
|
||||
{ yyval.list = symbol_list_new (yyvsp[0].symbol, yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 38:
|
||||
#line 254 "parse-gram.y"
|
||||
#line 255 "parse-gram.y"
|
||||
{ yyval.list = symbol_list_prepend (yyvsp[-1].list, yyvsp[0].symbol, yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 39:
|
||||
#line 260 "parse-gram.y"
|
||||
#line 261 "parse-gram.y"
|
||||
{
|
||||
current_type = yyvsp[0].string;
|
||||
}
|
||||
break;
|
||||
|
||||
case 40:
|
||||
#line 264 "parse-gram.y"
|
||||
#line 265 "parse-gram.y"
|
||||
{
|
||||
symbol_class_set (yyvsp[0].symbol, current_class);
|
||||
symbol_type_set (yyvsp[0].symbol, yylsp[0], current_type);
|
||||
@@ -1388,7 +1389,7 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 41:
|
||||
#line 269 "parse-gram.y"
|
||||
#line 270 "parse-gram.y"
|
||||
{
|
||||
symbol_class_set (yyvsp[-1].symbol, current_class);
|
||||
symbol_type_set (yyvsp[-1].symbol, yylsp[-1], current_type);
|
||||
@@ -1397,7 +1398,7 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 42:
|
||||
#line 275 "parse-gram.y"
|
||||
#line 276 "parse-gram.y"
|
||||
{
|
||||
symbol_class_set (yyvsp[-1].symbol, current_class);
|
||||
symbol_type_set (yyvsp[-1].symbol, yylsp[-1], current_type);
|
||||
@@ -1406,7 +1407,7 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 43:
|
||||
#line 281 "parse-gram.y"
|
||||
#line 282 "parse-gram.y"
|
||||
{
|
||||
symbol_class_set (yyvsp[-2].symbol, current_class);
|
||||
symbol_type_set (yyvsp[-2].symbol, yylsp[-2], current_type);
|
||||
@@ -1416,77 +1417,77 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 44:
|
||||
#line 292 "parse-gram.y"
|
||||
#line 293 "parse-gram.y"
|
||||
{;}
|
||||
break;
|
||||
|
||||
case 45:
|
||||
#line 294 "parse-gram.y"
|
||||
#line 295 "parse-gram.y"
|
||||
{;}
|
||||
break;
|
||||
|
||||
case 50:
|
||||
#line 316 "parse-gram.y"
|
||||
#line 317 "parse-gram.y"
|
||||
{ current_lhs = yyvsp[-1].symbol; current_lhs_location = yylsp[-1]; }
|
||||
break;
|
||||
|
||||
case 51:
|
||||
#line 317 "parse-gram.y"
|
||||
#line 318 "parse-gram.y"
|
||||
{;}
|
||||
break;
|
||||
|
||||
case 52:
|
||||
#line 321 "parse-gram.y"
|
||||
{ grammar_rule_end (yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 53:
|
||||
#line 322 "parse-gram.y"
|
||||
{ grammar_rule_end (yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 53:
|
||||
#line 323 "parse-gram.y"
|
||||
{ grammar_rule_end (yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 54:
|
||||
#line 327 "parse-gram.y"
|
||||
#line 328 "parse-gram.y"
|
||||
{ grammar_rule_begin (current_lhs, current_lhs_location); }
|
||||
break;
|
||||
|
||||
case 55:
|
||||
#line 329 "parse-gram.y"
|
||||
#line 330 "parse-gram.y"
|
||||
{ grammar_current_rule_symbol_append (yyvsp[0].symbol, yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 56:
|
||||
#line 331 "parse-gram.y"
|
||||
#line 332 "parse-gram.y"
|
||||
{ grammar_current_rule_action_append (yyvsp[0].string, yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 57:
|
||||
#line 333 "parse-gram.y"
|
||||
#line 334 "parse-gram.y"
|
||||
{ grammar_current_rule_prec_set (yyvsp[0].symbol); }
|
||||
break;
|
||||
|
||||
case 58:
|
||||
#line 337 "parse-gram.y"
|
||||
{ yyval.symbol = yyvsp[0].symbol; }
|
||||
break;
|
||||
|
||||
case 59:
|
||||
#line 338 "parse-gram.y"
|
||||
{ yyval.symbol = yyvsp[0].symbol; }
|
||||
break;
|
||||
|
||||
case 60:
|
||||
case 59:
|
||||
#line 339 "parse-gram.y"
|
||||
{ yyval.symbol = yyvsp[0].symbol; }
|
||||
break;
|
||||
|
||||
case 60:
|
||||
#line 340 "parse-gram.y"
|
||||
{ yyval.symbol = getsym (yyvsp[0].string, yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 61:
|
||||
#line 344 "parse-gram.y"
|
||||
#line 345 "parse-gram.y"
|
||||
{ yyval.string = yyvsp[0].string; }
|
||||
break;
|
||||
|
||||
case 62:
|
||||
#line 350 "parse-gram.y"
|
||||
#line 351 "parse-gram.y"
|
||||
{
|
||||
yyval.symbol = getsym (yyvsp[0].string, yylsp[0]);
|
||||
symbol_class_set (yyval.symbol, token_sym);
|
||||
@@ -1494,7 +1495,7 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 63:
|
||||
#line 359 "parse-gram.y"
|
||||
#line 360 "parse-gram.y"
|
||||
{
|
||||
yyval.string = yyvsp[0].string + 1;
|
||||
yyval.string[strlen (yyval.string) - 1] = '\0';
|
||||
@@ -1502,14 +1503,14 @@ yyreduce:
|
||||
break;
|
||||
|
||||
case 64:
|
||||
#line 367 "parse-gram.y"
|
||||
#line 368 "parse-gram.y"
|
||||
{
|
||||
yyval.string = xstrdup ("");
|
||||
}
|
||||
break;
|
||||
|
||||
case 65:
|
||||
#line 371 "parse-gram.y"
|
||||
#line 372 "parse-gram.y"
|
||||
{
|
||||
yyval.string = yyvsp[0].string;
|
||||
}
|
||||
@@ -1519,7 +1520,7 @@ yyreduce:
|
||||
}
|
||||
|
||||
/* Line 1012 of /usr/local/share/bison/bison.simple. */
|
||||
#line 1523 "parse-gram.c"
|
||||
#line 1524 "parse-gram.c"
|
||||
|
||||
yyvsp -= yylen;
|
||||
yyssp -= yylen;
|
||||
@@ -1740,7 +1741,7 @@ yyreturn:
|
||||
return yyresult;
|
||||
}
|
||||
|
||||
#line 380 "parse-gram.y"
|
||||
#line 381 "parse-gram.y"
|
||||
|
||||
/*------------------------------------------------------------------.
|
||||
| When debugging the parser, display tokens' locations and values. |
|
||||
|
||||
@@ -93,10 +93,10 @@
|
||||
|
||||
|
||||
#ifndef YYSTYPE
|
||||
#line 89 "parse-gram.y"
|
||||
#line 90 "parse-gram.y"
|
||||
typedef union {
|
||||
symbol_t *symbol;
|
||||
symbol_list *list;
|
||||
symbol_list_t *list;
|
||||
int integer;
|
||||
char *string;
|
||||
associativity assoc;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "files.h"
|
||||
#include "getargs.h"
|
||||
#include "output.h"
|
||||
#include "symlist.h"
|
||||
#include "gram.h"
|
||||
#include "reader.h"
|
||||
#include "conflicts.h"
|
||||
@@ -88,7 +89,7 @@ int current_prec = 0;
|
||||
%union
|
||||
{
|
||||
symbol_t *symbol;
|
||||
symbol_list *list;
|
||||
symbol_list_t *list;
|
||||
int integer;
|
||||
char *string;
|
||||
associativity assoc;
|
||||
@@ -214,24 +215,24 @@ symbol_declaration:
|
||||
}
|
||||
| "%type" TYPE symbols.1
|
||||
{
|
||||
symbol_list *list;
|
||||
symbol_list_t *list;
|
||||
for (list = $3; list; list = list->next)
|
||||
symbol_type_set (list->sym, list->location, $2);
|
||||
LIST_FREE (symbol_list, $3);
|
||||
LIST_FREE (symbol_list_t, $3);
|
||||
}
|
||||
;
|
||||
|
||||
precedence_declaration:
|
||||
precedence_declarator type.opt symbols.1
|
||||
{
|
||||
symbol_list *list;
|
||||
symbol_list_t *list;
|
||||
++current_prec;
|
||||
for (list = $3; list; list = list->next)
|
||||
{
|
||||
symbol_type_set (list->sym, list->location, current_type);
|
||||
symbol_precedence_set (list->sym, list->location, current_prec, $1);
|
||||
}
|
||||
LIST_FREE (symbol_list, $3);
|
||||
LIST_FREE (symbol_list_t, $3);
|
||||
current_type = NULL;
|
||||
}
|
||||
;
|
||||
|
||||
79
src/reader.c
79
src/reader.c
@@ -26,6 +26,7 @@
|
||||
#include "getargs.h"
|
||||
#include "files.h"
|
||||
#include "symtab.h"
|
||||
#include "symlist.h"
|
||||
#include "options.h"
|
||||
#include "gram.h"
|
||||
#include "complain.h"
|
||||
@@ -35,68 +36,12 @@
|
||||
#include "muscle_tab.h"
|
||||
|
||||
int lineno;
|
||||
static symbol_list *grammar = NULL;
|
||||
static symbol_list_t *grammar = NULL;
|
||||
static int start_flag = 0;
|
||||
|
||||
/* Nonzero if %union has been seen. */
|
||||
int typed = 0;
|
||||
|
||||
symbol_list *
|
||||
symbol_list_new (symbol_t *sym, location_t location)
|
||||
{
|
||||
symbol_list *res = XMALLOC (symbol_list, 1);
|
||||
res->next = NULL;
|
||||
res->sym = sym;
|
||||
res->location = location;
|
||||
res->action = NULL;
|
||||
res->ruleprec = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
symbol_list *
|
||||
symbol_list_prepend (symbol_list *list, symbol_t *symbol, location_t location)
|
||||
{
|
||||
symbol_list *res = symbol_list_new (symbol, location);
|
||||
res->next = list;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------.
|
||||
| Get the data type (alternative in the union) of the value for |
|
||||
| symbol N in rule RULE. |
|
||||
`--------------------------------------------------------------*/
|
||||
|
||||
char *
|
||||
get_type_name (int n, symbol_list *rule)
|
||||
{
|
||||
int i;
|
||||
symbol_list *rp;
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
complain (_("invalid $ value"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rp = rule;
|
||||
i = 0;
|
||||
|
||||
while (i < n)
|
||||
{
|
||||
rp = rp->next;
|
||||
if (rp == NULL || rp->sym == NULL)
|
||||
{
|
||||
complain (_("invalid $ value"));
|
||||
return NULL;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return rp->sym->type_name;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------.
|
||||
| Set the start symbol. |
|
||||
`-----------------------*/
|
||||
@@ -183,7 +128,7 @@ gensym (location_t location)
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
| Parse the input grammar into a one symbol_list structure. Each |
|
||||
| Parse the input grammar into a one symbol_list_t structure. Each |
|
||||
| rule is represented by a sequence of symbols: the left hand side |
|
||||
| followed by the contents of the right hand side, followed by a |
|
||||
| null pointer instead of a symbol to terminate the rule. The next |
|
||||
@@ -201,13 +146,13 @@ gensym (location_t location)
|
||||
`-------------------------------------------------------------------*/
|
||||
|
||||
/* The (currently) last symbol of GRAMMAR. */
|
||||
symbol_list *grammar_end = NULL;
|
||||
symbol_list_t *grammar_end = NULL;
|
||||
|
||||
/* Append S to the GRAMMAR. */
|
||||
void
|
||||
grammar_symbol_append (symbol_t *symbol, location_t location)
|
||||
{
|
||||
symbol_list *p = symbol_list_new (symbol, location);
|
||||
symbol_list_t *p = symbol_list_new (symbol, location);
|
||||
|
||||
if (grammar_end)
|
||||
grammar_end->next = p;
|
||||
@@ -220,8 +165,8 @@ grammar_symbol_append (symbol_t *symbol, location_t location)
|
||||
/* The rule currently being defined, and the previous rule.
|
||||
CURRENT_RULE points to the first LHS of the current rule, while
|
||||
PREVIOUS_RULE_END points to the *end* of the previous rule (NULL). */
|
||||
symbol_list *current_rule = NULL;
|
||||
symbol_list *previous_rule_end = NULL;
|
||||
symbol_list_t *current_rule = NULL;
|
||||
symbol_list_t *previous_rule_end = NULL;
|
||||
|
||||
|
||||
/*----------------------------------------------.
|
||||
@@ -323,7 +268,7 @@ grammar_midrule_action (void)
|
||||
action. Create the MIDRULE. */
|
||||
location_t dummy_location = current_rule->action_location;
|
||||
symbol_t *dummy = gensym (dummy_location);
|
||||
symbol_list *midrule = symbol_list_new (dummy, dummy_location);
|
||||
symbol_list_t *midrule = symbol_list_new (dummy, dummy_location);
|
||||
|
||||
/* Make a new rule, whose body is empty, before the current one, so
|
||||
that the action just read can belong to it. */
|
||||
@@ -397,7 +342,7 @@ packgram (void)
|
||||
{
|
||||
unsigned int itemno;
|
||||
int ruleno;
|
||||
symbol_list *p;
|
||||
symbol_list_t *p;
|
||||
|
||||
ritem = XCALLOC (item_number_t, nritems);
|
||||
rules = XCALLOC (rule_t, nrules) - 1;
|
||||
@@ -518,7 +463,7 @@ reader (void)
|
||||
|
||||
axiom: %start EOF. */
|
||||
{
|
||||
symbol_list *p = symbol_list_new (axiom, empty_location);
|
||||
symbol_list_t *p = symbol_list_new (axiom, empty_location);
|
||||
p->location = grammar->location;
|
||||
p->next = symbol_list_new (startsymbol, empty_location);
|
||||
p->next->next = symbol_list_new (eoftoken, empty_location);
|
||||
@@ -544,6 +489,6 @@ reader (void)
|
||||
/* Convert the grammar into the format described in gram.h. */
|
||||
packgram ();
|
||||
|
||||
/* The grammar as a symbol_list is no longer needed. */
|
||||
LIST_FREE (symbol_list, grammar);
|
||||
/* The grammar as a symbol_list_t is no longer needed. */
|
||||
LIST_FREE (symbol_list_t, grammar);
|
||||
}
|
||||
|
||||
23
src/reader.h
23
src/reader.h
@@ -21,25 +21,7 @@
|
||||
#ifndef READER_H_
|
||||
# define READER_H_
|
||||
|
||||
# include "location.h"
|
||||
|
||||
typedef struct symbol_list
|
||||
{
|
||||
struct symbol_list *next;
|
||||
symbol_t *sym;
|
||||
location_t location;
|
||||
|
||||
/* The action is attached to the LHS of a rule. */
|
||||
const char *action;
|
||||
location_t action_location;
|
||||
|
||||
symbol_t *ruleprec;
|
||||
} symbol_list;
|
||||
|
||||
symbol_list *symbol_list_new PARAMS ((symbol_t *sym, location_t location));
|
||||
symbol_list *symbol_list_prepend PARAMS ((symbol_list *list,
|
||||
symbol_t *sym, location_t location));
|
||||
|
||||
# include "symlist.h"
|
||||
# include "parse-gram.h"
|
||||
|
||||
typedef struct gram_control_s
|
||||
@@ -66,7 +48,6 @@ void gram_error (gram_control_t *control,
|
||||
location_t *loc, const char *msg);
|
||||
int gram_parse (void *control);
|
||||
|
||||
char *get_type_name PARAMS ((int n, symbol_list *rule));
|
||||
extern int typed;
|
||||
|
||||
/* From reader.c. */
|
||||
@@ -82,7 +63,7 @@ void grammar_current_rule_symbol_append PARAMS ((symbol_t *symbol,
|
||||
location_t l));
|
||||
void grammar_current_rule_action_append PARAMS ((const char *action,
|
||||
location_t l));
|
||||
extern symbol_list *current_rule;
|
||||
extern symbol_list_t *current_rule;
|
||||
void reader PARAMS ((void));
|
||||
|
||||
#endif /* !READER_H_ */
|
||||
|
||||
@@ -790,7 +790,7 @@ scanner_last_string_free (void)
|
||||
static int braces_level = 0;
|
||||
static int percent_percent_count = 0;
|
||||
|
||||
static void handle_dollar PARAMS ((char *cp));
|
||||
static void handle_dollar PARAMS ((char *cp, location_t location));
|
||||
static void handle_at PARAMS ((char *cp));
|
||||
|
||||
#define SC_COMMENT 1
|
||||
@@ -1696,7 +1696,7 @@ YY_OBS_GROW; braces_level++;
|
||||
case 82:
|
||||
YY_RULE_SETUP
|
||||
#line 444 "scan-gram.l"
|
||||
{ handle_dollar (yytext); }
|
||||
{ handle_dollar (yytext, *yylloc); }
|
||||
YY_BREAK
|
||||
case 83:
|
||||
YY_RULE_SETUP
|
||||
@@ -2701,7 +2701,7 @@ int main()
|
||||
`------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
handle_dollar (char *cp)
|
||||
handle_dollar (char *cp, location_t location)
|
||||
{
|
||||
const char *type_name = NULL;
|
||||
|
||||
@@ -2710,7 +2710,7 @@ handle_dollar (char *cp)
|
||||
stack. It is not the same as the rule->length in the case of mid
|
||||
rule actions. */
|
||||
int rule_length = 0;
|
||||
symbol_list *rhs;
|
||||
symbol_list_t *rhs;
|
||||
for (rhs = current_rule->next; rhs; rhs = rhs->next)
|
||||
++rule_length;
|
||||
|
||||
@@ -2729,10 +2729,10 @@ handle_dollar (char *cp)
|
||||
if (*cp == '$')
|
||||
{
|
||||
if (!type_name)
|
||||
type_name = get_type_name (0, current_rule);
|
||||
type_name = symbol_list_n_type_name_get (current_rule, location, 0);
|
||||
if (!type_name && typed)
|
||||
complain (_("$$ of `%s' has no declared type"),
|
||||
current_rule->sym->tag);
|
||||
complain_at (location, _("$$ of `%s' has no declared type"),
|
||||
current_rule->sym->tag);
|
||||
if (!type_name)
|
||||
type_name = "";
|
||||
obstack_fgrow1 (&string_obstack,
|
||||
@@ -2743,13 +2743,14 @@ handle_dollar (char *cp)
|
||||
int n = strtol (cp, &cp, 10);
|
||||
|
||||
if (n > rule_length)
|
||||
complain (_("invalid value: %s%d"), "$", n);
|
||||
complain_at (location, _("invalid value: %s%d"), "$", n);
|
||||
else
|
||||
{
|
||||
if (!type_name && n > 0)
|
||||
type_name = get_type_name (n, current_rule);
|
||||
type_name = symbol_list_n_type_name_get (current_rule, location,
|
||||
n);
|
||||
if (!type_name && typed)
|
||||
complain (_("$%d of `%s' has no declared type"),
|
||||
complain_at (location, _("$%d of `%s' has no declared type"),
|
||||
n, current_rule->sym->tag);
|
||||
if (!type_name)
|
||||
type_name = "";
|
||||
@@ -2779,7 +2780,7 @@ handle_at (char *cp)
|
||||
stack. It is not the same as the rule->length in the case of mid
|
||||
rule actions. */
|
||||
int rule_length = 0;
|
||||
symbol_list *rhs;
|
||||
symbol_list_t *rhs;
|
||||
for (rhs = current_rule->next; rhs; rhs = rhs->next)
|
||||
++rule_length;
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ scanner_last_string_free (void)
|
||||
static int braces_level = 0;
|
||||
static int percent_percent_count = 0;
|
||||
|
||||
static void handle_dollar PARAMS ((char *cp));
|
||||
static void handle_dollar PARAMS ((char *cp, location_t location));
|
||||
static void handle_at PARAMS ((char *cp));
|
||||
|
||||
%}
|
||||
@@ -441,7 +441,7 @@ blanks [ \t\f]+
|
||||
|
||||
"{" YY_OBS_GROW; braces_level++;
|
||||
|
||||
"$"("<"[^>]+">")?(-?[0-9]+|"$") { handle_dollar (yytext); }
|
||||
"$"("<"[^>]+">")?(-?[0-9]+|"$") { handle_dollar (yytext, *yylloc); }
|
||||
"@"(-?[0-9]+|"$") { handle_at (yytext); }
|
||||
|
||||
[^$@\[\]/\'\"\{\}\n\r]+ YY_OBS_GROW;
|
||||
@@ -520,7 +520,7 @@ blanks [ \t\f]+
|
||||
`------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
handle_dollar (char *cp)
|
||||
handle_dollar (char *cp, location_t location)
|
||||
{
|
||||
const char *type_name = NULL;
|
||||
|
||||
@@ -529,7 +529,7 @@ handle_dollar (char *cp)
|
||||
stack. It is not the same as the rule->length in the case of mid
|
||||
rule actions. */
|
||||
int rule_length = 0;
|
||||
symbol_list *rhs;
|
||||
symbol_list_t *rhs;
|
||||
for (rhs = current_rule->next; rhs; rhs = rhs->next)
|
||||
++rule_length;
|
||||
|
||||
@@ -548,10 +548,10 @@ handle_dollar (char *cp)
|
||||
if (*cp == '$')
|
||||
{
|
||||
if (!type_name)
|
||||
type_name = get_type_name (0, current_rule);
|
||||
type_name = symbol_list_n_type_name_get (current_rule, location, 0);
|
||||
if (!type_name && typed)
|
||||
complain (_("$$ of `%s' has no declared type"),
|
||||
current_rule->sym->tag);
|
||||
complain_at (location, _("$$ of `%s' has no declared type"),
|
||||
current_rule->sym->tag);
|
||||
if (!type_name)
|
||||
type_name = "";
|
||||
obstack_fgrow1 (&string_obstack,
|
||||
@@ -562,13 +562,14 @@ handle_dollar (char *cp)
|
||||
int n = strtol (cp, &cp, 10);
|
||||
|
||||
if (n > rule_length)
|
||||
complain (_("invalid value: %s%d"), "$", n);
|
||||
complain_at (location, _("invalid value: %s%d"), "$", n);
|
||||
else
|
||||
{
|
||||
if (!type_name && n > 0)
|
||||
type_name = get_type_name (n, current_rule);
|
||||
type_name = symbol_list_n_type_name_get (current_rule, location,
|
||||
n);
|
||||
if (!type_name && typed)
|
||||
complain (_("$%d of `%s' has no declared type"),
|
||||
complain_at (location, _("$%d of `%s' has no declared type"),
|
||||
n, current_rule->sym->tag);
|
||||
if (!type_name)
|
||||
type_name = "";
|
||||
@@ -598,7 +599,7 @@ handle_at (char *cp)
|
||||
stack. It is not the same as the rule->length in the case of mid
|
||||
rule actions. */
|
||||
int rule_length = 0;
|
||||
symbol_list *rhs;
|
||||
symbol_list_t *rhs;
|
||||
for (rhs = current_rule->next; rhs; rhs = rhs->next)
|
||||
++rule_length;
|
||||
|
||||
|
||||
99
src/symlist.c
Normal file
99
src/symlist.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/* Lists of symbols for Bison
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
Bison is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
Bison is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bison; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include "system.h"
|
||||
#include "symlist.h"
|
||||
|
||||
|
||||
/*----------------------------------------------.
|
||||
| Create a list containing SYMBOL at LOCATION. |
|
||||
`----------------------------------------------*/
|
||||
|
||||
symbol_list_t *
|
||||
symbol_list_new (symbol_t *sym, location_t location)
|
||||
{
|
||||
symbol_list_t *res = XMALLOC (symbol_list_t, 1);
|
||||
res->next = NULL;
|
||||
res->sym = sym;
|
||||
res->location = location;
|
||||
res->action = NULL;
|
||||
res->ruleprec = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------.
|
||||
| Prepend SYMBOL at LOCATION to the LIST. |
|
||||
`-----------------------------------------*/
|
||||
|
||||
symbol_list_t *
|
||||
symbol_list_prepend (symbol_list_t *list,
|
||||
symbol_t *symbol, location_t location)
|
||||
{
|
||||
symbol_list_t *res = symbol_list_new (symbol, location);
|
||||
res->next = list;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------.
|
||||
| Free the LIST, but not the symbols it contains. |
|
||||
`-------------------------------------------------*/
|
||||
|
||||
void
|
||||
symbol_list_free (symbol_list_t *list)
|
||||
{
|
||||
LIST_FREE (symbol_list_t, list);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------.
|
||||
| Get the data type (alternative in the union) of the value for |
|
||||
| symbol N in rule RULE. |
|
||||
`--------------------------------------------------------------*/
|
||||
|
||||
char *
|
||||
symbol_list_n_type_name_get (symbol_list_t *rule, location_t location, int n)
|
||||
{
|
||||
int i;
|
||||
symbol_list_t *rp;
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
complain_at (location, _("invalid $ value"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rp = rule;
|
||||
i = 0;
|
||||
|
||||
while (i < n)
|
||||
{
|
||||
rp = rp->next;
|
||||
if (rp == NULL || rp->sym == NULL)
|
||||
{
|
||||
complain_at (location, _("invalid $ value"));
|
||||
return NULL;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return rp->sym->type_name;
|
||||
}
|
||||
60
src/symlist.h
Normal file
60
src/symlist.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* Lists of symbols for Bison
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
Bison is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
Bison is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bison; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef SYMLIST_H_
|
||||
# define SYMLIST_H_
|
||||
|
||||
# include "symtab.h"
|
||||
# include "location.h"
|
||||
|
||||
typedef struct symbol_list_s
|
||||
{
|
||||
struct symbol_list_s *next;
|
||||
symbol_t *sym;
|
||||
location_t location;
|
||||
|
||||
/* The action is attached to the LHS of a rule. */
|
||||
const char *action;
|
||||
location_t action_location;
|
||||
|
||||
symbol_t *ruleprec;
|
||||
} symbol_list_t;
|
||||
|
||||
|
||||
/* Create a list containing SYMBOL at LOCATION. */
|
||||
symbol_list_t *symbol_list_new PARAMS ((symbol_t *sym, location_t location));
|
||||
|
||||
|
||||
/* Prepend SYMBOL at LOCATION to the LIST. */
|
||||
symbol_list_t * symbol_list_prepend PARAMS ((symbol_list_t *list,
|
||||
symbol_t *symbol,
|
||||
location_t location));
|
||||
|
||||
|
||||
/* Free the LIST, but not the symbols it contains. */
|
||||
void symbol_list_free PARAMS ((symbol_list_t *list));
|
||||
|
||||
|
||||
/* Get the data type (alternative in the union) of the value for
|
||||
symbol N in rule RULE. */
|
||||
char *symbol_list_n_type_name_get PARAMS ((symbol_list_t *rule,
|
||||
location_t location, int n));
|
||||
|
||||
#endif /* !SYMLIST_H_ */
|
||||
@@ -57,7 +57,7 @@ exp: { $$ = $1 ; };
|
||||
]])
|
||||
|
||||
AT_CHECK([bison input.y], [1], [],
|
||||
[[input.y:2: invalid value: $1
|
||||
[[input.y:2.6-14: invalid value: $1
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
Reference in New Issue
Block a user