36 |
#include "conflicts.h" |
#include "conflicts.h" |
37 |
#include "muscle_tab.h" |
#include "muscle_tab.h" |
38 |
|
|
|
/* Number of slots allocated (but not necessarily used yet) in `rline' */ |
|
|
static int rline_allocated; |
|
|
|
|
39 |
typedef struct symbol_list |
typedef struct symbol_list |
40 |
{ |
{ |
41 |
struct symbol_list *next; |
struct symbol_list *next; |
42 |
bucket *sym; |
bucket *sym; |
43 |
|
int line; |
44 |
bucket *ruleprec; |
bucket *ruleprec; |
45 |
} |
} |
46 |
symbol_list; |
symbol_list; |
64 |
|
|
65 |
static bucket *errtoken; |
static bucket *errtoken; |
66 |
static bucket *undeftoken; |
static bucket *undeftoken; |
67 |
|
|
68 |
|
|
69 |
|
symbol_list * |
70 |
|
symbol_list_new (bucket *sym) |
71 |
|
{ |
72 |
|
symbol_list *res = XMALLOC (symbol_list, 1); |
73 |
|
res->next = NULL; |
74 |
|
res->sym = sym; |
75 |
|
res->line = lineno; |
76 |
|
res->ruleprec = NULL; |
77 |
|
return res; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
/*===================\ |
/*===================\ |
134 |
`--------------------------------------------------------------*/ |
`--------------------------------------------------------------*/ |
135 |
|
|
136 |
static char * |
static char * |
137 |
get_type_name (int n, symbol_list * rule) |
get_type_name (int n, symbol_list *rule) |
138 |
{ |
{ |
139 |
int i; |
int i; |
140 |
symbol_list *rp; |
symbol_list *rp; |
579 |
else |
else |
580 |
{ |
{ |
581 |
complain (_("`%s' is invalid in %s"), |
complain (_("`%s' is invalid in %s"), |
582 |
token_buffer, (what_is == token_sym) ? "%token" : "%nterm"); |
token_buffer, |
583 |
|
(what_is == token_sym) ? "%token" : "%nterm"); |
584 |
skip_to_char ('%'); |
skip_to_char ('%'); |
585 |
} |
} |
586 |
} |
} |
1405 |
nrules++; |
nrules++; |
1406 |
nitems++; |
nitems++; |
1407 |
|
|
1408 |
p = XCALLOC (symbol_list, 1); |
p = symbol_list_new (lhs); |
|
p->sym = lhs; |
|
1409 |
|
|
1410 |
crule1 = p1; |
crule1 = p1; |
1411 |
if (p1) |
if (p1) |
1467 |
non-terminal. */ |
non-terminal. */ |
1468 |
if (action_flag) |
if (action_flag) |
1469 |
{ |
{ |
|
bucket *sdummy; |
|
|
|
|
1470 |
/* Since the action was written out with this rule's |
/* Since the action was written out with this rule's |
1471 |
number, we must give the new rule this number by |
number, we must give the new rule this number by |
1472 |
inserting the new rule before it. */ |
inserting the new rule before it. */ |
1473 |
|
|
1474 |
/* Make a dummy nonterminal, a gensym. */ |
/* Make a dummy nonterminal, a gensym. */ |
1475 |
sdummy = gensym (); |
bucket *sdummy = gensym (); |
1476 |
|
|
1477 |
/* Make a new rule, whose body is empty, |
/* Make a new rule, whose body is empty, |
1478 |
before the current one, so that the action |
before the current one, so that the action |
1479 |
just read can belong to it. */ |
just read can belong to it. */ |
1480 |
nrules++; |
nrules++; |
1481 |
nitems++; |
nitems++; |
1482 |
p = XCALLOC (symbol_list, 1); |
p = symbol_list_new (sdummy); |
1483 |
if (crule1) |
if (crule1) |
1484 |
crule1->next = p; |
crule1->next = p; |
1485 |
else |
else |
1486 |
grammar = p; |
grammar = p; |
1487 |
p->sym = sdummy; |
/* End of the rule. */ |
1488 |
crule1 = XCALLOC (symbol_list, 1); |
crule1 = symbol_list_new (NULL); |
1489 |
crule1->next = crule; |
crule1->next = crule; |
1490 |
|
|
1491 |
p->next = crule1; |
p->next = crule1; |
1493 |
/* Insert the dummy generated by that rule into this |
/* Insert the dummy generated by that rule into this |
1494 |
rule. */ |
rule. */ |
1495 |
nitems++; |
nitems++; |
1496 |
p = XCALLOC (symbol_list, 1); |
p = symbol_list_new (sdummy); |
|
p->sym = sdummy; |
|
1497 |
p1->next = p; |
p1->next = p; |
1498 |
p1 = p; |
p1 = p; |
1499 |
|
|
1503 |
if (t == tok_identifier) |
if (t == tok_identifier) |
1504 |
{ |
{ |
1505 |
nitems++; |
nitems++; |
1506 |
p = XCALLOC (symbol_list, 1); |
p = symbol_list_new (symval); |
|
p->sym = symval; |
|
1507 |
p1->next = p; |
p1->next = p; |
1508 |
p1 = p; |
p1 = p; |
1509 |
} |
} |
1517 |
} /* end of read rhs of rule */ |
} /* end of read rhs of rule */ |
1518 |
|
|
1519 |
/* 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 */ |
1520 |
p = XCALLOC (symbol_list, 1); |
p = symbol_list_new (NULL); |
1521 |
p1->next = p; |
p1->next = p; |
1522 |
p1 = p; |
p1 = p; |
1523 |
|
|
1910 |
int ruleno; |
int ruleno; |
1911 |
symbol_list *p; |
symbol_list *p; |
1912 |
|
|
|
bucket *ruleprec; |
|
|
|
|
1913 |
ritem = XCALLOC (short, nitems + 1); |
ritem = XCALLOC (short, nitems + 1); |
1914 |
rule_table = XCALLOC (rule_t, nrules) - 1; |
rule_table = XCALLOC (rule_t, nrules) - 1; |
1915 |
|
|
1919 |
p = grammar; |
p = grammar; |
1920 |
while (p) |
while (p) |
1921 |
{ |
{ |
1922 |
|
bucket *ruleprec = p->ruleprec; |
1923 |
rule_table[ruleno].lhs = p->sym->value; |
rule_table[ruleno].lhs = p->sym->value; |
1924 |
rule_table[ruleno].rhs = itemno; |
rule_table[ruleno].rhs = itemno; |
1925 |
rule_table[ruleno].line = p->sym->line; |
rule_table[ruleno].line = p->line; |
|
ruleprec = p->ruleprec; |
|
1926 |
|
|
1927 |
p = p->next; |
p = p->next; |
1928 |
while (p && p->sym) |
while (p && p->sym) |