summaryrefslogtreecommitdiff
path: root/src/bsr.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/bsr.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/bsr.c')
-rw-r--r--src/bsr.c16
1 files changed, 12 insertions, 4 deletions
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