summaryrefslogtreecommitdiff
path: root/src/grammar.h
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-11-09 20:03:23 +0800
committerJSDurand <mmemmew@gmail.com>2021-11-09 20:03:23 +0800
commit53b8b6ffab5a968db75e9babddf4e2dbb2c688a3 (patch)
tree4ff55ae0027544b06702d24ec4840a2011f724e9 /src/grammar.h
parent87b6bad500702b0fcd708ee5b1d99f61a29ec7e6 (diff)
save point: representation of grammar might be too rough.
The current representation of the grammar is the most primitive BNF. This is the simplest to implement, but is difficult to cope with user requirements. Moreover, I find another paper describing the GLR algorithm, so I need to think about the representation of the grammar more. In particular, I would like the generation of the grammar to be incremental, so per chance its data type should be adapted accordingly.
Diffstat (limited to 'src/grammar.h')
-rw-r--r--src/grammar.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/grammar.h b/src/grammar.h
index 2baec68..8353dd5 100644
--- a/src/grammar.h
+++ b/src/grammar.h
@@ -22,8 +22,14 @@ typedef unsigned NT;
typedef struct TNT_s TNT;
typedef struct Rule_s Rule;
-/* A grammar is a list of rules. */
-typedef List *Grammar;
+/* A grammar is more than a list of rules: it should include a
+ correspondance to associate the names of non-terminals with
+ unsigned integers. Basically, this means it should hold a list of
+ strings as well. */
+typedef struct Grammar_s Grammar;
+
+/* G is expected to be allocated before this function. */
+void build_grammar(Grammar *g, List *rules, List *names);
/* This accepts one and only one optional argument, which is of type
either T or NT, depending on TYPE being 0 or not. */
@@ -32,12 +38,14 @@ TNT *new_tnt(int type, ...);
/* For debugging purposes, we need to print out rules to examine their
values. */
+void print_name(void *element);
+
void print_tnt(void *element);
void print_rule(void *r);
/* This will generate errors if G is not a list of rules. */
-void print_grammar(Grammar g);
+void print_grammar(Grammar *g);
/* constructors */
@@ -53,7 +61,13 @@ List *new_tnt_string(char *format, int format_len, ...);
If RIGHT is NULL, NULL is returned. */
Rule *new_rule(NT left, List *right);
+Grammar *new_grammar();
+
/* destructors */
-void destroy_rule(Rule *rule);
+void destroy_rule(void *rule, int flag);
+void destroy_rule_and_free_all(void *rule);
+void destroy_rule_and_free_first(void *rule);
+void destroy_rule_no_free(void *rule);
+void destroy_grammar(void *grammar, int flag);
#endif