Attaching lineno to buckets is stupid, since only one copy of each

symbol is kept, only the line of the first occurrence is kept too.
* src/symtab.h, src/symtab.c (bucket): Remove the line member.
* src/reader.c (rline_allocated): Remove, unused.
(symbol_list): Have a `line' member.
(symbol_list_new): New.
(readgram): Use it.
* src/print.c (print_grammar): Output the rule line numbers.
* tests/regression.at (Solved SR Conflicts)
(Unresolved SR Conflicts): Adjust.
Reported by Hans Aberg.
This commit is contained in:
Akim Demaille
2001-11-23 14:13:02 +00:00
parent b497173564
commit b29b2ed560
6 changed files with 52 additions and 35 deletions

View File

@@ -1,3 +1,18 @@
2001-11-23 Akim Demaille <akim@epita.fr>
Attaching lineno to buckets is stupid, since only one copy of each
symbol is kept, only the line of the first occurrence is kept too.
* src/symtab.h, src/symtab.c (bucket): Remove the line member.
* src/reader.c (rline_allocated): Remove, unused.
(symbol_list): Have a `line' member.
(symbol_list_new): New.
(readgram): Use it.
* src/print.c (print_grammar): Output the rule line numbers.
* tests/regression.at (Solved SR Conflicts)
(Unresolved SR Conflicts): Adjust.
Reported by Hans Aberg.
2001-11-22 Marc Autret <autret_m@epita.fr> 2001-11-22 Marc Autret <autret_m@epita.fr>
* src/bison.simple [YYERROR_VERBOSE]: Force its value to be 1 or 0. * src/bison.simple [YYERROR_VERBOSE]: Force its value to be 1 or 0.

View File

@@ -213,17 +213,19 @@ print_grammar (FILE *out)
/* rule # : LHS -> RHS */ /* rule # : LHS -> RHS */
fprintf (out, "\n%s\n\n", _("Grammar")); fprintf (out, "\n%s\n\n", _("Grammar"));
fprintf (out, " %s\n", _("Number, Line, Rule"));
for (i = 1; i <= nrules; i++) for (i = 1; i <= nrules; i++)
/* Don't print rules disabled in reduce_grammar_tables. */ /* Don't print rules disabled in reduce_grammar_tables. */
if (rule_table[i].lhs >= 0) if (rule_table[i].lhs >= 0)
{ {
fprintf (out, _("rule %-4d %s ->"), i, tags[rule_table[i].lhs]); fprintf (out, _(" %3d %3d %s ->"),
i, rule_table[i].line, tags[rule_table[i].lhs]);
rule = &ritem[rule_table[i].rhs]; rule = &ritem[rule_table[i].rhs];
if (*rule > 0) if (*rule > 0)
while (*rule > 0) while (*rule > 0)
fprintf (out, " %s", tags[*rule++]); fprintf (out, " %s", tags[*rule++]);
else else
fprintf (out, " /* %s */", _("empty")); fprintf (out, " /* %s */", _("empty"));
fputc ('\n', out); fputc ('\n', out);
} }

View File

@@ -36,13 +36,11 @@
#include "conflicts.h" #include "conflicts.h"
#include "muscle_tab.h" #include "muscle_tab.h"
/* Number of slots allocated (but not necessarily used yet) in `rline' */
static int rline_allocated;
typedef struct symbol_list typedef struct symbol_list
{ {
struct symbol_list *next; struct symbol_list *next;
bucket *sym; bucket *sym;
int line;
bucket *ruleprec; bucket *ruleprec;
} }
symbol_list; symbol_list;
@@ -66,6 +64,19 @@ static int lastprec;
static bucket *errtoken; static bucket *errtoken;
static bucket *undeftoken; static bucket *undeftoken;
symbol_list *
symbol_list_new (bucket *sym)
{
symbol_list *res = XMALLOC (symbol_list, 1);
res->next = NULL;
res->sym = sym;
res->line = lineno;
res->ruleprec = NULL;
return res;
}
/*===================\ /*===================\
@@ -123,7 +134,7 @@ read_signed_integer (FILE *stream)
`--------------------------------------------------------------*/ `--------------------------------------------------------------*/
static char * static char *
get_type_name (int n, symbol_list * rule) get_type_name (int n, symbol_list *rule)
{ {
int i; int i;
symbol_list *rp; symbol_list *rp;
@@ -568,7 +579,8 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
else else
{ {
complain (_("`%s' is invalid in %s"), complain (_("`%s' is invalid in %s"),
token_buffer, (what_is == token_sym) ? "%token" : "%nterm"); token_buffer,
(what_is == token_sym) ? "%token" : "%nterm");
skip_to_char ('%'); skip_to_char ('%');
} }
} }
@@ -1393,8 +1405,7 @@ readgram (void)
nrules++; nrules++;
nitems++; nitems++;
p = XCALLOC (symbol_list, 1); p = symbol_list_new (lhs);
p->sym = lhs;
crule1 = p1; crule1 = p1;
if (p1) if (p1)
@@ -1456,27 +1467,25 @@ readgram (void)
non-terminal. */ non-terminal. */
if (action_flag) if (action_flag)
{ {
bucket *sdummy;
/* Since the action was written out with this rule's /* Since the action was written out with this rule's
number, we must give the new rule this number by number, we must give the new rule this number by
inserting the new rule before it. */ inserting the new rule before it. */
/* Make a dummy nonterminal, a gensym. */ /* Make a dummy nonterminal, a gensym. */
sdummy = gensym (); bucket *sdummy = gensym ();
/* Make a new rule, whose body is empty, /* Make a new rule, whose body is empty,
before the current one, so that the action before the current one, so that the action
just read can belong to it. */ just read can belong to it. */
nrules++; nrules++;
nitems++; nitems++;
p = XCALLOC (symbol_list, 1); p = symbol_list_new (sdummy);
if (crule1) if (crule1)
crule1->next = p; crule1->next = p;
else else
grammar = p; grammar = p;
p->sym = sdummy; /* End of the rule. */
crule1 = XCALLOC (symbol_list, 1); crule1 = symbol_list_new (NULL);
crule1->next = crule; crule1->next = crule;
p->next = crule1; p->next = crule1;
@@ -1484,8 +1493,7 @@ readgram (void)
/* Insert the dummy generated by that rule into this /* Insert the dummy generated by that rule into this
rule. */ rule. */
nitems++; nitems++;
p = XCALLOC (symbol_list, 1); p = symbol_list_new (sdummy);
p->sym = sdummy;
p1->next = p; p1->next = p;
p1 = p; p1 = p;
@@ -1495,8 +1503,7 @@ readgram (void)
if (t == tok_identifier) if (t == tok_identifier)
{ {
nitems++; nitems++;
p = XCALLOC (symbol_list, 1); p = symbol_list_new (symval);
p->sym = symval;
p1->next = p; p1->next = p;
p1 = p; p1 = p;
} }
@@ -1510,7 +1517,7 @@ readgram (void)
} /* end of read rhs of rule */ } /* end of read rhs of rule */
/* Put an empty link in the list to mark the end of this rule */ /* Put an empty link in the list to mark the end of this rule */
p = XCALLOC (symbol_list, 1); p = symbol_list_new (NULL);
p1->next = p; p1->next = p;
p1 = p; p1 = p;
@@ -1903,8 +1910,6 @@ packgram (void)
int ruleno; int ruleno;
symbol_list *p; symbol_list *p;
bucket *ruleprec;
ritem = XCALLOC (short, nitems + 1); ritem = XCALLOC (short, nitems + 1);
rule_table = XCALLOC (rule_t, nrules) - 1; rule_table = XCALLOC (rule_t, nrules) - 1;
@@ -1914,10 +1919,10 @@ packgram (void)
p = grammar; p = grammar;
while (p) while (p)
{ {
bucket *ruleprec = p->ruleprec;
rule_table[ruleno].lhs = p->sym->value; rule_table[ruleno].lhs = p->sym->value;
rule_table[ruleno].rhs = itemno; rule_table[ruleno].rhs = itemno;
rule_table[ruleno].line = p->sym->line; rule_table[ruleno].line = p->line;
ruleprec = p->ruleprec;
p = p->next; p = p->next;
while (p && p->sym) while (p && p->sym)

View File

@@ -49,9 +49,6 @@ hash (const char *key)
static bucket * static bucket *
bucket_new (const char *tag, int hashval) bucket_new (const char *tag, int hashval)
{ {
/* Hack, until we have a Bison parser. */
extern int lineno;
bucket *res = XMALLOC (bucket, 1); bucket *res = XMALLOC (bucket, 1);
res->link = symtab[hashval]; res->link = symtab[hashval];
@@ -64,7 +61,6 @@ bucket_new (const char *tag, int hashval)
res->user_token_number = SUNDEF; res->user_token_number = SUNDEF;
res->alias = NULL; res->alias = NULL;
res->class = unknown_sym; res->class = unknown_sym;
res->line = lineno;
nsyms++; nsyms++;

View File

@@ -42,9 +42,6 @@ typedef struct bucket
struct bucket *link; struct bucket *link;
struct bucket *next; struct bucket *next;
/* The line it was found in. */
short line;
/* The key, name of the symbol. */ /* The key, name of the symbol. */
char *tag; char *tag;
/* Its type. */ /* Its type. */

View File

@@ -65,8 +65,9 @@ AT_CHECK([cat input.output], [],
Grammar Grammar
rule 1 exp -> exp OP exp Number, Line, Rule
rule 2 exp -> NUM 1 3 exp -> exp OP exp
2 3 exp -> NUM
Terminals, with rules where they appear Terminals, with rules where they appear
@@ -163,8 +164,9 @@ AT_CHECK([cat input.output], [],
Grammar Grammar
rule 1 exp -> exp OP exp Number, Line, Rule
rule 2 exp -> NUM 1 4 exp -> exp OP exp
2 4 exp -> NUM
Terminals, with rules where they appear Terminals, with rules where they appear