From a8bd5e9d85ac9928bd29add82e887f82642af893 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Mon, 31 Jan 2022 09:23:20 +0800 Subject: 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. --- src/grammar.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/grammar.c') 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); -- cgit v1.2.3-18-g5258