- for (r = ritem; *r; ++r)
- {
- /* Walk RITEM to find (i), if there are any tokens in the
- RHS, and (ii), to find RULENO. */
- int ruleno;
- int any_tokens = 0;
- short *r1;
- for (r1 = r; *r1 > 0; ++r1)
- if (ISTOKEN (*r1))
- any_tokens = 1;
- ruleno = -*r1;
-
- /* Examine the RHS of the rule. */
- if (!any_tokens)
- for (/* Nothing. */; *r > 0; ++r)
- {
- rcount[ruleno]++;
- p->next = rsets[*r];
- p->value = ruleno;
- rsets[*r] = p;
- p++;
- }
-
- /* Examine its LHS. */
- if (rule_table[ruleno].useful && !nullable[rule_table[ruleno].lhs])
- {
- nullable[rule_table[ruleno].lhs] = 1;
- *s2++ = rule_table[ruleno].lhs;
- }
- }
+ for (ruleno = 0; ruleno < nrules; ++ruleno)
+ if (rules[ruleno].useful)
+ {
+ rule *rules_ruleno = &rules[ruleno];
+ if (rules_ruleno->rhs[0] >= 0)
+ {
+ /* This rule has a non empty RHS. */
+ item_number *rp = NULL;
+ bool any_tokens = false;
+ for (rp = rules_ruleno->rhs; *rp >= 0; ++rp)
+ if (ISTOKEN (*rp))
+ any_tokens = true;
+
+ /* This rule has only nonterminals: schedule it for the second
+ pass. */
+ if (!any_tokens)
+ for (rp = rules_ruleno->rhs; *rp >= 0; ++rp)
+ {
+ rcount[ruleno]++;
+ p->next = rsets[*rp - ntokens];
+ p->value = rules_ruleno;
+ rsets[*rp - ntokens] = p;
+ p++;
+ }
+ }
+ else
+ {
+ /* This rule has an empty RHS. */
+ aver (item_number_as_rule_number (rules_ruleno->rhs[0])
+ == ruleno);
+ if (rules_ruleno->useful
+ && ! nullable[rules_ruleno->lhs->number - ntokens])
+ {
+ nullable[rules_ruleno->lhs->number - ntokens] = true;
+ *s2++ = rules_ruleno->lhs->number;
+ }
+ }
+ }