summaryrefslogtreecommitdiff
path: root/src/grammar.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/grammar.h')
-rw-r--r--src/grammar.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/grammar.h b/src/grammar.h
new file mode 100644
index 0000000..2baec68
--- /dev/null
+++ b/src/grammar.h
@@ -0,0 +1,59 @@
+#ifndef GRAMMAR_H
+#define GRAMMAR_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include "list.h"
+
+/* The class file for grammars */
+
+/* A grammar is a list of rules. A rule replaces a non-terminal with
+ a finite string of terminals and non-terminals.
+
+ For us, a terminal is a positive integer, and a non-terminal is a
+ negative integer. Since the signs of these two types is fixed, we
+ represent them as unsigned integers. Since we want to deal with
+ unicode points, the terminal is stored as unsigned long, so that we
+ can include all unicode poitns. */
+
+typedef unsigned long T;
+typedef unsigned NT;
+
+typedef struct TNT_s TNT;
+typedef struct Rule_s Rule;
+
+/* A grammar is a list of rules. */
+typedef List *Grammar;
+
+/* This accepts one and only one optional argument, which is of type
+ either T or NT, depending on TYPE being 0 or not. */
+TNT *new_tnt(int type, ...);
+
+/* For debugging purposes, we need to print out rules to examine their
+ values. */
+
+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);
+
+/* constructors */
+
+/* FORMAT specifies the types of TNTs. It is a string of t and n's.
+ FORMAT_LEN is the length of FORMAT, excluding the terminating null
+ byte.
+
+ Upon failure NULL is returned. */
+List *new_tnt_string(char *format, int format_len, ...);
+
+/* RIGHT should be created by new_tnt_string or something alike.
+
+ If RIGHT is NULL, NULL is returned. */
+Rule *new_rule(NT left, List *right);
+
+/* destructors */
+void destroy_rule(Rule *rule);
+
+#endif