[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/17] reader: get ready to create several initial rules
From: |
Akim Demaille |
Subject: |
[PATCH 02/17] reader: get ready to create several initial rules |
Date: |
Sun, 20 Sep 2020 10:37:34 +0200 |
* src/reader.c (create_start_rule): New.
Use it.
---
src/reader.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/src/reader.c b/src/reader.c
index 0f9b7ee4..6932decd 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -764,6 +764,33 @@ find_start_symbol (void)
}
+/* Insert an initial rule, whose location is that of the first rule
+ (not that of the start symbol):
+
+ $accept: SWITCHING_TOKEN START $end. */
+static void
+create_start_rule (symbol *swtok, symbol *start)
+{
+ symbol_list *initial_rule = symbol_list_sym_new (acceptsymbol, empty_loc);
+ initial_rule->rhs_loc = grammar->rhs_loc;
+ symbol_list *p = initial_rule;
+ if (swtok)
+ {
+ p->next = symbol_list_sym_new (swtok, empty_loc);
+ p = p->next;
+ }
+ p->next = symbol_list_sym_new (start, empty_loc);
+ p = p->next;
+ p->next = symbol_list_sym_new (eoftoken, empty_loc);
+ p = p->next;
+ p->next = symbol_list_sym_new (NULL, empty_loc);
+ p = p->next;
+ p->next = grammar;
+ nrules += 1;
+ nritems += 3 + !!swtok;
+ grammar = initial_rule;
+}
+
/*-------------------------------------------------------------.
| Check the grammar that has just been read, and convert it to |
| internal form. |
@@ -801,21 +828,8 @@ check_and_convert_grammar (void)
grammar_start_symbol_set (start, start->location);
}
- /* Insert the initial rule, whose line is that of the first rule
- (not that of the start symbol):
-
- $accept: %start $end. */
- {
- symbol_list *p = symbol_list_sym_new (acceptsymbol, empty_loc);
- p->rhs_loc = grammar->rhs_loc;
- p->next = symbol_list_sym_new (startsymbol, empty_loc);
- p->next->next = symbol_list_sym_new (eoftoken, empty_loc);
- p->next->next->next = symbol_list_sym_new (NULL, empty_loc);
- p->next->next->next->next = grammar;
- nrules += 1;
- nritems += 3;
- grammar = p;
- }
+ /* Insert the initial rule. */
+ create_start_rule (NULL, startsymbol);
if (SYMBOL_NUMBER_MAXIMUM - nnterms < ntokens)
complain (NULL, fatal, "too many symbols in input grammar (limit is %d)",
--
2.28.0
- [PATCH 00/17] RFC: multiple start symbols, Akim Demaille, 2020/09/20
- [PATCH 01/17] gram: more debugging information, Akim Demaille, 2020/09/20
- [PATCH 02/17] reader: get ready to create several initial rules,
Akim Demaille <=
- [PATCH 03/17] parser: expose a list of symbols, Akim Demaille, 2020/09/20
- [PATCH 04/17] regen, Akim Demaille, 2020/09/20
- [PATCH 05/17] multistart: turn start symbols into rules on $accept, Akim Demaille, 2020/09/20
- [PATCH 06/17] regen, Akim Demaille, 2020/09/20
- [PATCH 07/17] multistart: adjust computation of initial core and adjust reports, Akim Demaille, 2020/09/20
- [PATCH 08/17] multistart: also check the HTML report, Akim Demaille, 2020/09/20
- [PATCH 09/17] multistart: pass the list of start symbols to the backend, Akim Demaille, 2020/09/20
- [PATCH 10/17] multistart: equip yacc.c, Akim Demaille, 2020/09/20
- [PATCH 11/17] multistart: toy with it in lexcalc, Akim Demaille, 2020/09/20
- [PATCH 12/17] todo: more, Akim Demaille, 2020/09/20