summaryrefslogtreecommitdiff
path: root/src/cnp.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/cnp.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/cnp.h')
-rw-r--r--src/cnp.h61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/cnp.h b/src/cnp.h
index 5944ca3..2b0c104 100644
--- a/src/cnp.h
+++ b/src/cnp.h
@@ -1,4 +1,63 @@
#ifndef CNP_H
#define CNP_H
-/* TODO */
+#include "str.h"
+#include "utf8.h"
+#include "bsr.h"
+#include "crf.h"
+
+/* We start with implementing some support functions. These support
+ functions are not supposed to be put in the crf.h header file, as
+ they are not related to the underlying (static) data structures
+ really. */
+
+typedef struct Environment_s Environment;
+
+/* On error return NULL */
+Environment *new_env(Grammar *g, str *string);
+
+HP_ATTR BOOL env_error_p(CCR_MOD(Environment *) env);
+
+P_ATTR bsr *env_bsrp(CCR_MOD(Environment *) env);
+
+P_ATTR Grammar *env_grammar(CCR_MOD(Environment *) env);
+
+HP_ATTR crf *env_crfp(CCR_MOD(Environment *) env);
+
+HP_ATTR procr *env_r(CCR_MOD(Environment *) env);
+HP_ATTR procu *env_u(CCR_MOD(Environment *) env);
+H_ATTR void env_str(CCR_MOD(Environment *) env,
+ NUM **str, NUM *str_len);
+
+H_ATTR BOOL env_follow_p(CCR_MOD(Environment *) env, NUM X, NUM t);
+
+void env_print_follow(CCR_MOD(Environment *) env, NUM X);
+
+void env_print_first(CCR_MOD(Environment *) env, NUM X);
+
+/* Convenient macro */
+
+#define CHECK_ENV_ERROR(ENV, CLEANUP) do { \
+ if (env_error_p(ENV)) { \
+ fleprintf0("Error occurs!\n"); \
+ { CLEANUP }; \
+ } \
+ } while (0)
+
+/* NOTE: Since the grammar pointer just points to the existing grammar
+ when we construct it, we shall not destroy the grammar when we
+ destroy the environment, so that we can later reuse that grammar,
+ should the need arise. */
+void destroy_env(Environment *env);
+
+void nt_add(Environment *env, NUM X, NUM j);
+
+BOOL test_select(Environment *env, NUM b, NUM X,
+ CCR_MOD(List *) tnts);
+
+void rtn(Environment *env, NUM X, NUM k, NUM j);
+
+void cnp_call(Environment *env, pair3 label, NUM i, NUM j);
+
+/* TODO: Main algorithm */
+
#endif