mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 01:03:04 +00:00
* 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:
@@ -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>
|
2002-06-10 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
GCJ's parser requires the tokens to be defined before the prologue.
|
GCJ's parser requires the tokens to be defined before the prologue.
|
||||||
|
|||||||
67
src/reader.c
67
src/reader.c
@@ -1072,13 +1072,28 @@ gensym (void)
|
|||||||
| in the rules section. |
|
| 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
|
static void
|
||||||
readgram (void)
|
readgram (void)
|
||||||
{
|
{
|
||||||
token_t t;
|
token_t t;
|
||||||
symbol_t *lhs = NULL;
|
symbol_t *lhs = NULL;
|
||||||
symbol_list *p = NULL;
|
|
||||||
symbol_list *p1 = NULL;
|
|
||||||
|
|
||||||
/* Points to first symbol_list of current rule. its symbol is the
|
/* Points to first symbol_list of current rule. its symbol is the
|
||||||
lhs of the rule. */
|
lhs of the rule. */
|
||||||
@@ -1125,16 +1140,9 @@ readgram (void)
|
|||||||
++nrules;
|
++nrules;
|
||||||
++nritems;
|
++nritems;
|
||||||
|
|
||||||
p = symbol_list_new (lhs);
|
crule1 = grammar_end;
|
||||||
|
grammar_symbol_append (lhs);
|
||||||
crule1 = p1;
|
crule = grammar_end;
|
||||||
if (p1)
|
|
||||||
p1->next = p;
|
|
||||||
else
|
|
||||||
grammar = p;
|
|
||||||
|
|
||||||
p1 = p;
|
|
||||||
crule = p;
|
|
||||||
|
|
||||||
/* mark the rule's lhs as a nonterminal if not already so. */
|
/* mark the rule's lhs as a nonterminal if not already so. */
|
||||||
|
|
||||||
@@ -1196,13 +1204,13 @@ readgram (void)
|
|||||||
|
|
||||||
/* Make a dummy nonterminal, a gensym. */
|
/* Make a dummy nonterminal, a gensym. */
|
||||||
symbol_t *sdummy = gensym ();
|
symbol_t *sdummy = gensym ();
|
||||||
|
symbol_list *p = symbol_list_new (sdummy);
|
||||||
|
|
||||||
/* Make a new rule, whose body is empty, before the
|
/* Make a new rule, whose body is empty, before the
|
||||||
current one, so that the action just read can
|
current one, so that the action just read can
|
||||||
belong to it. */
|
belong to it. */
|
||||||
++nrules;
|
++nrules;
|
||||||
++nritems;
|
++nritems;
|
||||||
p = symbol_list_new (sdummy);
|
|
||||||
/* Attach its lineno to that of the host rule. */
|
/* Attach its lineno to that of the host rule. */
|
||||||
p->line = crule->line;
|
p->line = crule->line;
|
||||||
/* Move the action from the host rule to this one. */
|
/* 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
|
/* Insert the dummy generated by that rule into this
|
||||||
rule. */
|
rule. */
|
||||||
++nritems;
|
++nritems;
|
||||||
p = symbol_list_new (sdummy);
|
grammar_symbol_append (sdummy);
|
||||||
p1->next = p;
|
|
||||||
p1 = p;
|
|
||||||
|
|
||||||
action_flag = 0;
|
action_flag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t == tok_identifier)
|
if (t == tok_identifier)
|
||||||
{
|
{
|
||||||
++nritems;
|
++nritems;
|
||||||
p = symbol_list_new (symval);
|
grammar_symbol_append (symval);
|
||||||
p1->next = p;
|
|
||||||
p1 = p;
|
|
||||||
}
|
}
|
||||||
else /* handle an action. */
|
else /* handle an action. */
|
||||||
{
|
{
|
||||||
@@ -1247,9 +1250,7 @@ readgram (void)
|
|||||||
} /* end of read rhs of rule */
|
} /* end of read rhs of rule */
|
||||||
|
|
||||||
/* Put an empty link in the list to mark the end of this rule */
|
/* Put an empty link in the list to mark the end of this rule */
|
||||||
p = symbol_list_new (NULL);
|
grammar_symbol_append (NULL);
|
||||||
p1->next = p;
|
|
||||||
p1 = p;
|
|
||||||
|
|
||||||
if (t == tok_prec)
|
if (t == tok_prec)
|
||||||
{
|
{
|
||||||
@@ -1307,15 +1308,17 @@ readgram (void)
|
|||||||
(not that of the start symbol):
|
(not that of the start symbol):
|
||||||
|
|
||||||
axiom: %start EOF. */
|
axiom: %start EOF. */
|
||||||
p = symbol_list_new (axiom);
|
{
|
||||||
p->line = grammar->line;
|
symbol_list *p = symbol_list_new (axiom);
|
||||||
p->next = symbol_list_new (startsymbol);
|
p->line = grammar->line;
|
||||||
p->next->next = symbol_list_new (eoftoken);
|
p->next = symbol_list_new (startsymbol);
|
||||||
p->next->next->next = symbol_list_new (NULL);
|
p->next->next = symbol_list_new (eoftoken);
|
||||||
p->next->next->next->next = grammar;
|
p->next->next->next = symbol_list_new (NULL);
|
||||||
nrules += 1;
|
p->next->next->next->next = grammar;
|
||||||
nritems += 3;
|
nrules += 1;
|
||||||
grammar = p;
|
nritems += 3;
|
||||||
|
grammar = p;
|
||||||
|
}
|
||||||
|
|
||||||
if (nsyms > SHRT_MAX)
|
if (nsyms > SHRT_MAX)
|
||||||
fatal (_("too many symbols (tokens plus nonterminals); maximum %d"),
|
fatal (_("too many symbols (tokens plus nonterminals); maximum %d"),
|
||||||
|
|||||||
Reference in New Issue
Block a user