(rule_t): this.
* src/conflicts.c, src/reader.c, src/reduce.c: Adjust.
+2001-11-19 Akim Demaille <akim@epita.fr>
+
+ * src/gram.h (rprec, rprecsym, rassoc): Remove, now part of...
+ (rule_t): this.
+ * src/conflicts.c, src/reader.c, src/reduce.c: Adjust.
+
2001-11-19 Akim Demaille <akim@epita.fr>
* src/gram.h (rule_t): New.
2001-11-19 Akim Demaille <akim@epita.fr>
* src/gram.h (rule_t): New.
short *errtokens = errp->errs;
/* find the rule to reduce by to get precedence of reduction */
short *errtokens = errp->errs;
/* find the rule to reduce by to get precedence of reduction */
- redprec = rprec[LAruleno[lookaheadnum]];
+ redprec = rule_table[LAruleno[lookaheadnum]].prec;
mask = 1;
fp1 = LA (lookaheadnum);
mask = 1;
fp1 = LA (lookaheadnum);
check for shift-reduce conflict, and try to resolve using
precedence */
for (i = state_table[state].lookaheads; i < k; i++)
check for shift-reduce conflict, and try to resolve using
precedence */
for (i = state_table[state].lookaheads; i < k; i++)
- if (rprec[LAruleno[i]])
+ if (rule_table[LAruleno[i]].prec)
{
fp1 = LA (i);
fp2 = fp1;
{
fp1 = LA (i);
fp2 = fp1;
RULE_TABLE[R].rhs -- the index in RITEM of the beginning of the
portion for rule R.
RULE_TABLE[R].rhs -- the index in RITEM of the beginning of the
portion for rule R.
+ RULE_TABLE[R].prec -- the precedence level of R.
+
+ RULE_TABLE[R].precsym -- the symbol-number of the symbol in %prec
+ for R (if any).
+
+ RULE_TABLE[R].assoc -- the associativity of the rule.
+
The right hand side is stored as symbol numbers in a portion of
RITEM.
The right hand side is stored as symbol numbers in a portion of
RITEM.
Item numbers are used in the finite state machine to represent
places that parsing can get to.
Item numbers are used in the finite state machine to represent
places that parsing can get to.
- Precedence levels are recorded in the vectors sprec and rprec.
- sprec records the precedence level of each symbol, rprec the
- precedence level of each rule. rprecsym is the symbol-number of
- the symbol in %prec for this rule (if any).
+ SPREC records the precedence level of each symbol.
Precedence levels are assigned in increasing order starting with 1
so that numerically higher precedence values mean tighter binding
Precedence levels are assigned in increasing order starting with 1
so that numerically higher precedence values mean tighter binding
-extern short *rprec;
-extern short *rprecsym;
extern short *sassoc;
extern short *rline; /* Source line number of each rule */
extern int start_symbol;
extern short *sassoc;
extern short *rline; /* Source line number of each rule */
extern int start_symbol;
-typedef struct rule_s
-{
- short lhs;
- short rhs;
-} rule_t;
-
-extern struct rule_s *rule_table;
-
/* associativity values in elements of rassoc, sassoc. */
typedef enum
{
/* associativity values in elements of rassoc, sassoc. */
typedef enum
{
+typedef struct rule_s
+{
+ short lhs;
+ short rhs;
+ short prec;
+ short precsym;
+ short assoc;
+} rule_t;
+
+extern struct rule_s *rule_table;
+
/* token translation table: indexed by a token number as returned by
the user's yylex routine, it yields the internal token number used
by the parser and throughout bison. */
/* token translation table: indexed by a token number as returned by
the user's yylex routine, it yields the internal token number used
by the parser and throughout bison. */
ritem = XCALLOC (short, nitems + 1);
rule_table = XCALLOC (rule_t, nrules) - 1;
ritem = XCALLOC (short, nitems + 1);
rule_table = XCALLOC (rule_t, nrules) - 1;
- rprec = XCALLOC (short, nrules) - 1;
- rprecsym = XCALLOC (short, nrules) - 1;
- rassoc = XCALLOC (short, nrules) - 1;
of the last token in it. */
if (p->sym->class == token_sym)
{
of the last token in it. */
if (p->sym->class == token_sym)
{
- rprec[ruleno] = p->sym->prec;
- rassoc[ruleno] = p->sym->assoc;
+ rule_table[ruleno].prec = p->sym->prec;
+ rule_table[ruleno].assoc = p->sym->assoc;
the specified symbol's precedence replaces the default. */
if (ruleprec)
{
the specified symbol's precedence replaces the default. */
if (ruleprec)
{
- rprec[ruleno] = ruleprec->prec;
- rassoc[ruleno] = ruleprec->assoc;
- rprecsym[ruleno] = ruleprec->value;
+ rule_table[ruleno].prec = ruleprec->prec;
+ rule_table[ruleno].assoc = ruleprec->assoc;
+ rule_table[ruleno].precsym = ruleprec->value;
}
ritem[itemno++] = -ruleno;
}
ritem[itemno++] = -ruleno;
/* A token that was used in %prec should not be warned about. */
for (i = 1; i < nrules; i++)
/* A token that was used in %prec should not be warned about. */
for (i = 1; i < nrules; i++)
- if (rprecsym[i] != 0)
- SETBIT (V1, rprecsym[i]);
+ if (rule_table[i].precsym != 0)
+ SETBIT (V1, rule_table[i].precsym);
{
rule_table[np].lhs = rule_table[pn].lhs;
rline[np] = rline[pn];
{
rule_table[np].lhs = rule_table[pn].lhs;
rline[np] = rline[pn];
- rprec[np] = rprec[pn];
- rassoc[np] = rassoc[pn];
+ rule_table[np].prec = rule_table[pn].prec;
+ rule_table[np].assoc = rule_table[pn].assoc;
rule_table[np].rhs = rule_table[pn].rhs;
if (rule_table[np].rhs != ni)
{
rule_table[np].rhs = rule_table[pn].rhs;
if (rule_table[np].rhs != ni)
{
/* Ignore the rules disabled above. */
if (rule_table[i].lhs >= 0)
rule_table[i].lhs = nontermmap[rule_table[i].lhs];
/* Ignore the rules disabled above. */
if (rule_table[i].lhs >= 0)
rule_table[i].lhs = nontermmap[rule_table[i].lhs];
- if (ISVAR (rprecsym[i]))
+ if (ISVAR (rule_table[i].precsym))
- rprecsym[i] = nontermmap[rprecsym[i]];
+ rule_table[i].precsym = nontermmap[rule_table[i].precsym];
}
for (r = ritem; *r; r++)
}
for (r = ritem; *r; r++)
for (i = 1; i <= nrules; i++)
{
fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)",
for (i = 1; i <= nrules; i++)
{
fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)",
- i, rprec[i], rassoc[i], rule_table[i].lhs, rule_table[i].rhs);
+ i,
+ rule_table[i].prec,
+ rule_table[i].assoc,
+ rule_table[i].lhs,
+ rule_table[i].rhs);
for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
fprintf (out, "%5d", *r);
fprintf (out, " [%d]\n", -(*r));
for (r = &ritem[rule_table[i].rhs]; *r > 0; r++)
fprintf (out, "%5d", *r);
fprintf (out, " [%d]\n", -(*r));