559 |
complain (_("symbol %s redefined"), symbol->tag); |
complain (_("symbol %s redefined"), symbol->tag); |
560 |
symbol->class = what_is; |
symbol->class = what_is; |
561 |
if (what_is == nterm_sym && oldclass != nterm_sym) |
if (what_is == nterm_sym && oldclass != nterm_sym) |
562 |
symbol->value = nvars++; |
symbol->number = nvars++; |
563 |
|
|
564 |
if (typename) |
if (typename) |
565 |
{ |
{ |
1202 |
token_buffer = buf; |
token_buffer = buf; |
1203 |
sym = getsym (token_buffer); |
sym = getsym (token_buffer); |
1204 |
sym->class = nterm_sym; |
sym->class = nterm_sym; |
1205 |
sym->value = nvars++; |
sym->number = nvars++; |
1206 |
return sym; |
return sym; |
1207 |
} |
} |
1208 |
|
|
1294 |
if (lhs->class == unknown_sym) |
if (lhs->class == unknown_sym) |
1295 |
{ |
{ |
1296 |
lhs->class = nterm_sym; |
lhs->class = nterm_sym; |
1297 |
lhs->value = nvars; |
lhs->number = nvars; |
1298 |
nvars++; |
nvars++; |
1299 |
} |
} |
1300 |
else if (lhs->class == token_sym) |
else if (lhs->class == token_sym) |
1471 |
("symbol %s is used, but is not defined as a token and has no rules"), |
("symbol %s is used, but is not defined as a token and has no rules"), |
1472 |
bp->tag); |
bp->tag); |
1473 |
bp->class = nterm_sym; |
bp->class = nterm_sym; |
1474 |
bp->value = nvars++; |
bp->number = nvars++; |
1475 |
} |
} |
1476 |
|
|
1477 |
/* Insert the initial rule, which line is that of the first rule |
/* Insert the initial rule, which line is that of the first rule |
1544 |
for (bp = firstsymbol; bp; bp = bp->next) |
for (bp = firstsymbol; bp; bp = bp->next) |
1545 |
{ |
{ |
1546 |
/* Non-terminal? */ |
/* Non-terminal? */ |
1547 |
if (bp->value >= ntokens) |
if (bp->number >= ntokens) |
1548 |
continue; |
continue; |
1549 |
/* A token string alias? */ |
/* A token string alias? */ |
1550 |
if (bp->user_token_number == SALIAS) |
if (bp->user_token_number == SALIAS) |
1557 |
complain (_("tokens %s and %s both assigned number %d"), |
complain (_("tokens %s and %s both assigned number %d"), |
1558 |
symbols[token_translations[bp->user_token_number]]->tag, |
symbols[token_translations[bp->user_token_number]]->tag, |
1559 |
bp->tag, bp->user_token_number); |
bp->tag, bp->user_token_number); |
1560 |
token_translations[bp->user_token_number] = bp->value; |
token_translations[bp->user_token_number] = bp->number; |
1561 |
} |
} |
1562 |
} |
} |
1563 |
|
|
1583 |
{ |
{ |
1584 |
if (bp->class == nterm_sym) |
if (bp->class == nterm_sym) |
1585 |
{ |
{ |
1586 |
bp->value += ntokens; |
bp->number += ntokens; |
1587 |
} |
} |
1588 |
else if (bp->alias) |
else if (bp->alias) |
1589 |
{ |
{ |
1590 |
/* This symbol and its alias are a single token defn. |
/* This symbol and its alias are a single token defn. |
1591 |
Allocate a tokno, and assign to both check agreement of |
Allocate a tokno, and assign to both check agreement of |
1592 |
prec and assoc fields and make both the same */ |
prec and assoc fields and make both the same */ |
1593 |
if (bp->value == -1) |
if (bp->number == -1) |
1594 |
{ |
{ |
1595 |
if (bp == eoftoken || bp->alias == eoftoken) |
if (bp == eoftoken || bp->alias == eoftoken) |
1596 |
bp->value = bp->alias->value = 0; |
bp->number = bp->alias->number = 0; |
1597 |
else |
else |
1598 |
{ |
{ |
1599 |
bp->value = bp->alias->value = tokno++; |
bp->number = bp->alias->number = tokno++; |
1600 |
} |
} |
1601 |
} |
} |
1602 |
|
|
1632 |
else /* bp->class == token_sym */ |
else /* bp->class == token_sym */ |
1633 |
{ |
{ |
1634 |
if (bp == eoftoken) |
if (bp == eoftoken) |
1635 |
bp->value = 0; |
bp->number = 0; |
1636 |
else |
else |
1637 |
bp->value = tokno++; |
bp->number = tokno++; |
1638 |
} |
} |
1639 |
|
|
1640 |
if (bp->class == token_sym) |
if (bp->class == token_sym) |
1645 |
max_user_token_number = bp->user_token_number; |
max_user_token_number = bp->user_token_number; |
1646 |
} |
} |
1647 |
|
|
1648 |
symbols[bp->value] = bp; |
symbols[bp->number] = bp; |
1649 |
} |
} |
1650 |
|
|
1651 |
token_translations_init (); |
token_translations_init (); |
1652 |
|
|
1653 |
error_token_number = errtoken->value; |
error_token_number = errtoken->number; |
1654 |
|
|
1655 |
if (startval->class == unknown_sym) |
if (startval->class == unknown_sym) |
1656 |
fatal (_("the start symbol %s is undefined"), startval->tag); |
fatal (_("the start symbol %s is undefined"), startval->tag); |
1657 |
else if (startval->class == token_sym) |
else if (startval->class == token_sym) |
1658 |
fatal (_("the start symbol %s is a token"), startval->tag); |
fatal (_("the start symbol %s is a token"), startval->tag); |
1659 |
|
|
1660 |
start_symbol = startval->value; |
start_symbol = startval->number; |
1661 |
} |
} |
1662 |
|
|
1663 |
|
|
1664 |
/*---------------------------------------------------------------. |
/*---------------------------------------------------------------. |
1665 |
| Convert the rules into the representation using RRHS, RLHS and | |
| Convert the rules into the representation using RRHS, RLHS and | |
1666 |
| RITEMS. | |
| RITEM. | |
1667 |
`---------------------------------------------------------------*/ |
`---------------------------------------------------------------*/ |
1668 |
|
|
1669 |
static void |
static void |
1687 |
while (p) |
while (p) |
1688 |
{ |
{ |
1689 |
bucket *ruleprec = p->ruleprec; |
bucket *ruleprec = p->ruleprec; |
1690 |
rules[ruleno].lhs = p->sym->value; |
rules[ruleno].lhs = p->sym->number; |
1691 |
rules[ruleno].rhs = ritem + itemno; |
rules[ruleno].rhs = ritem + itemno; |
1692 |
rules[ruleno].line = p->line; |
rules[ruleno].line = p->line; |
1693 |
rules[ruleno].useful = TRUE; |
rules[ruleno].useful = TRUE; |
1699 |
p = p->next; |
p = p->next; |
1700 |
while (p && p->sym) |
while (p && p->sym) |
1701 |
{ |
{ |
1702 |
ritem[itemno++] = p->sym->value; |
ritem[itemno++] = p->sym->number; |
1703 |
/* A rule gets by default the precedence and associativity |
/* A rule gets by default the precedence and associativity |
1704 |
of the last token in it. */ |
of the last token in it. */ |
1705 |
if (p->sym->class == token_sym) |
if (p->sym->class == token_sym) |
1717 |
{ |
{ |
1718 |
rules[ruleno].prec = ruleprec->prec; |
rules[ruleno].prec = ruleprec->prec; |
1719 |
rules[ruleno].assoc = ruleprec->assoc; |
rules[ruleno].assoc = ruleprec->assoc; |
1720 |
rules[ruleno].precsym = ruleprec->value; |
rules[ruleno].precsym = ruleprec->number; |
1721 |
} |
} |
1722 |
|
|
1723 |
ritem[itemno++] = -ruleno; |
ritem[itemno++] = -ruleno; |
1774 |
/* Construct the axiom symbol. */ |
/* Construct the axiom symbol. */ |
1775 |
axiom = getsym ("$axiom"); |
axiom = getsym ("$axiom"); |
1776 |
axiom->class = nterm_sym; |
axiom->class = nterm_sym; |
1777 |
axiom->value = nvars++; |
axiom->number = nvars++; |
1778 |
|
|
1779 |
/* Construct the error token */ |
/* Construct the error token */ |
1780 |
errtoken = getsym ("error"); |
errtoken = getsym ("error"); |