* src/reader.c (grammar_end, grammar_symbol_append): New.

(readgram): Use them.
Make the use of `p' as local as possible.
This commit is contained in:
Akim Demaille
2002-06-11 08:07:36 +00:00
parent 69078d4b3b
commit f6d0f937fd
2 changed files with 41 additions and 32 deletions

View File

@@ -1,3 +1,9 @@
2002-06-11 Akim Demaille <akim@epita.fr>
* src/reader.c (grammar_end, grammar_symbol_append): New.
(readgram): Use them.
Make the use of `p' as local as possible.
2002-06-10 Akim Demaille <akim@epita.fr>
GCJ's parser requires the tokens to be defined before the prologue.

View File

@@ -1072,13 +1072,28 @@ gensym (void)
| 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. */
@@ -1125,16 +1140,9 @@ readgram (void)
++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. */
@@ -1196,13 +1204,13 @@ readgram (void)
/* 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. */
@@ -1223,19 +1231,14 @@ readgram (void)
/* 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. */
{
@@ -1247,9 +1250,7 @@ readgram (void)
} /* 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)
{
@@ -1307,15 +1308,17 @@ readgram (void)
(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"),