[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01-grammar-symbol-append.patch
From: |
Akim Demaille |
Subject: |
01-grammar-symbol-append.patch |
Date: |
Tue, 11 Jun 2002 10:05:44 +0200 |
In the case you wonder what all this agitation is about, I have a Flex
+ Bison scanner + parser working. In order to hook the rest of Bison
easily on this new reader, I'm extracting the hooks from the current
reader.
Amusingly, it reveals bugs, just like when first rewriting of some
parts of the automaton computation: bugs just reveal themselves
without my even paying attention :)
One instance of what I'm referring to is the patch #4, where the test
suite started to fail. It was previous versions that should have
complained!
Index: ChangeLog
from Akim Demaille <address@hidden>
* src/reader.c (grammar_end, grammar_symbol_append): New.
(readgram): Use them.
Make the use of `p' as local as possible.
Index: src/reader.c
--- src/reader.c Sun, 09 Jun 2002 16:55:50 +0200 akim
+++ src/reader.c Mon, 10 Jun 2002 21:24:24 +0200 akim
@@ -1072,13 +1072,28 @@
| 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 @@
++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 @@
/* 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 @@
/* 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 @@
} /* 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 @@
(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"),
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 01-grammar-symbol-append.patch,
Akim Demaille <=