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/bsr.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/bsr.c') diff --git a/src/bsr.c b/src/bsr.c index e737d7a..bd0a84c 100644 --- a/src/bsr.c +++ b/src/bsr.c @@ -210,7 +210,6 @@ bsr_add(CCR_MOD(Grammar *) g, bsr * const restrict b, #define ARR (b->f.array+X) if (!(ARR->initialized)) { - ARR->initialized = 1; ARR->table = new_ht2(HT_INIT_CAP); if (ARR->table == NULL) { @@ -218,6 +217,8 @@ bsr_add(CCR_MOD(Grammar *) g, bsr * const restrict b, goto cleanup; } + ARR->initialized = 1; + value_table = new_ht2(HT_INIT_CAP); if (value_table == NULL) { @@ -358,6 +359,7 @@ bsr_add(CCR_MOD(Grammar *) g, bsr * const restrict b, #undef AR #undef ARR #undef ARRR + } goto success; @@ -472,6 +474,12 @@ bsr_find(CCR_MOD(bsr *) b, CCR_MOD(Grammar *) g, return result; } +static void +print_sep() +{ + printf(" "); +} + void bsr_print(CCR_MOD(bsr *) b, CCR_MOD(Grammar *) g, NUM line_len) { @@ -500,11 +508,11 @@ bsr_print(CCR_MOD(bsr *) b, CCR_MOD(Grammar *) g, NUM line_len) printf("("); print_name(list_nth(grammar_names(g), i)); printf(" := "); - map_list + map_list_between (rg_nth (grammar_rule(g, i), (*(VALUE_TABLE_KEYS+k))->x), - print_tnt); + print_tnt, print_sep); printf(", %ld, %ld, %ld)", (*(KEYS+j))->x, (*(VALUE_TABLE_KEYS+k))->y, @@ -589,7 +597,7 @@ bsr_print(CCR_MOD(bsr *) b, CCR_MOD(Grammar *) g, NUM line_len) } } } - + printf("\n"); #undef ELEMENT -- cgit v1.2.3-18-g5258