summaryrefslogtreecommitdiff
path: root/src/grammar.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-31 09:23:20 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-31 09:23:20 +0800
commita8bd5e9d85ac9928bd29add82e887f82642af893 (patch)
tree74e377f9fccffc2779ff97fa0bd8ad180b9c865c /src/grammar.c
parente555c88b8107caf886da229444c2bed1aaef6c2c (diff)
test/check_cnp: working algorithm
I now have a working algorithm in test/check_cnp. It can correctly parse the grammar for an esoteric language called "Brainfuck". This language does not matter. What matters is that it contains parentheses. So this shows that at least for grammars as complex as parentheses, this parser works well. Haha.
Diffstat (limited to 'src/grammar.c')
-rw-r--r--src/grammar.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/grammar.c b/src/grammar.c
index c12ddec..3b5a959 100644
--- a/src/grammar.c
+++ b/src/grammar.c
@@ -676,7 +676,7 @@ nt_first(CC_MOD(Grammar *) g, CCR_MOD(BOOL *) nts,
BOOL
tnt_first(CC_MOD(ht *) terminal_hts, CC_MOD(ht *) predicate_hts,
- CCR_MOD(BOOL *) nts, NUM len, List *tnts,
+ CCR_MOD(BOOL *) nts, NUM len, CCR_MOD(List *) tnts,
ht * const restrict result_terminals,
ht * const restrict result_predicates)
{
@@ -787,8 +787,8 @@ nt_follow(CC_MOD(Grammar *) g, CCR_MOD(BOOL *) nts,
Rule_group *rg = grammar_rule(g, (NT) i);
NUM rg_length = rg_len(rg);
- for (NUM j = 0; j < rg_length;) {
- List *string = rg_nth(rg, j++);
+ for (NUM j = 0; j < rg_length; j++) {
+ List *string = rg_nth(rg, j);
NUM string_len = list_length(string);
TNT *top = NULL;
@@ -842,13 +842,12 @@ nt_follow(CC_MOD(Grammar *) g, CCR_MOD(BOOL *) nts,
if (k+1 == string_len ||
(rest_produce_epsilon >= 0 &&
- rest_produce_epsilon <= k))
+ rest_produce_epsilon <= k+1))
goto add_to_follow;
break;
add_to_follow:
-
ht_len = ht_size(result_terminals+i);
keys = (NUM **) ht_keys(result_terminals+i);