| in the rules section. |
`-------------------------------------------------------------------*/
+/* The (currently) last symbol of GRAMMAR. */
+symbol_list *grammar_end = NULL;
+
+/* Append S to the GRAMMAR. */
+static void
+grammar_symbol_append (symbol_t *s)
+{
+ symbol_list *p = symbol_list_new (s);
+
+ if (grammar_end)
+ grammar_end->next = p;
+ else
+ grammar = p;
+
+ grammar_end = p;
+}
+
static void
readgram (void)
{
token_t t;
symbol_t *lhs = NULL;
- symbol_list *p = NULL;
- symbol_list *p1 = NULL;
/* Points to first symbol_list of current rule. its symbol is the
lhs of the rule. */
++nrules;
++nritems;
- p = symbol_list_new (lhs);
-
- crule1 = p1;
- if (p1)
- p1->next = p;
- else
- grammar = p;
-
- p1 = p;
- crule = p;
+ crule1 = grammar_end;
+ grammar_symbol_append (lhs);
+ crule = grammar_end;
/* mark the rule's lhs as a nonterminal if not already so. */
/* Make a dummy nonterminal, a gensym. */
symbol_t *sdummy = gensym ();
+ symbol_list *p = symbol_list_new (sdummy);
/* Make a new rule, whose body is empty, before the
current one, so that the action just read can
belong to it. */
++nrules;
++nritems;
- p = symbol_list_new (sdummy);
/* Attach its lineno to that of the host rule. */
p->line = crule->line;
/* Move the action from the host rule to this one. */
/* Insert the dummy generated by that rule into this
rule. */
++nritems;
- p = symbol_list_new (sdummy);
- p1->next = p;
- p1 = p;
-
+ grammar_symbol_append (sdummy);
action_flag = 0;
}
if (t == tok_identifier)
{
++nritems;
- p = symbol_list_new (symval);
- p1->next = p;
- p1 = p;
+ grammar_symbol_append (symval);
}
else /* handle an action. */
{
} /* end of read rhs of rule */
/* Put an empty link in the list to mark the end of this rule */
- p = symbol_list_new (NULL);
- p1->next = p;
- p1 = p;
+ grammar_symbol_append (NULL);
if (t == tok_prec)
{
(not that of the start symbol):
axiom: %start EOF. */
- p = symbol_list_new (axiom);
- p->line = grammar->line;
- p->next = symbol_list_new (startsymbol);
- p->next->next = symbol_list_new (eoftoken);
- p->next->next->next = symbol_list_new (NULL);
- p->next->next->next->next = grammar;
- nrules += 1;
- nritems += 3;
- grammar = p;
+ {
+ symbol_list *p = symbol_list_new (axiom);
+ p->line = grammar->line;
+ p->next = symbol_list_new (startsymbol);
+ p->next->next = symbol_list_new (eoftoken);
+ p->next->next->next = symbol_list_new (NULL);
+ p->next->next->next->next = grammar;
+ nrules += 1;
+ nritems += 3;
+ grammar = p;
+ }
if (nsyms > SHRT_MAX)
fatal (_("too many symbols (tokens plus nonterminals); maximum %d"),