summaryrefslogtreecommitdiff
path: root/src/grammar.h
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.h
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.h')
-rw-r--r--src/grammar.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/grammar.h b/src/grammar.h
index 8d6cb06..cbda887 100644
--- a/src/grammar.h
+++ b/src/grammar.h
@@ -213,7 +213,7 @@ BOOL nt_first(CC_MOD(Grammar *) g, CCR_MOD(BOOL *) nts,
On error return non-zero. */
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);
@@ -231,6 +231,27 @@ BOOL nt_follow(CC_MOD(Grammar *) g, CCR_MOD(BOOL *) nts,
ht * const result_terminals,
ht * const result_predicates);
+/* struct that holds information about grammars */
+
+typedef struct grammar_info_s grammar_info;
+
+struct grammar_info_s {
+ /* the grammar itself */
+ Grammar *g;
+ /* the array about epsilon non-terminals */
+ BOOL *nts;
+ /* the array of hash tables of first (premier) terminals */
+ ht *pts;
+ /* the array of hash tables of first (premier) predicate
+ terminals */
+ ht *pps;
+ /* the array of hash tables of follow (suivant) terminals */
+ ht *sts;
+ /* the array of hash tables of follow (suivant) predicate
+ terminals */
+ ht *sps;
+};
+
/* convenient macro */
#define NEW_CPA(X, ARRAY, SIZE) do { \