diff options
Diffstat (limited to 'src/grammar.h')
-rw-r--r-- | src/grammar.h | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/grammar.h b/src/grammar.h index 8353dd5..05bc1fc 100644 --- a/src/grammar.h +++ b/src/grammar.h @@ -4,6 +4,7 @@ #include <stdarg.h> #include <stdio.h> #include "list.h" +#include "utf8.h" /* The class file for grammars */ @@ -19,6 +20,15 @@ typedef unsigned long T; typedef unsigned NT; +/* T or NT + + Don't worry, it is not explosive. */ + +struct TNT_s { + int type; /* 0 => T and NT otherwise */ + union { T t; NT nt; } data; +}; + typedef struct TNT_s TNT; typedef struct Rule_s Rule; @@ -28,16 +38,30 @@ typedef struct Rule_s Rule; 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); +/* G is expected to be allocated before this function. + + NAMES is a list of CPA pointers. */ +unsigned char 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. */ TNT *new_tnt(int type, ...); +/* An array of code-points. */ + +struct cpa_s { + NUM *array; + UNUM size; +}; + +typedef struct cpa_s cpa; + +NUM find_in_cpa_list(NUM *string, NUM size, List *list); + /* For debugging purposes, we need to print out rules to examine their values. */ +/* assume element is a cpa pointer */ void print_name(void *element); void print_tnt(void *element); @@ -56,6 +80,8 @@ void print_grammar(Grammar *g); Upon failure NULL is returned. */ List *new_tnt_string(char *format, int format_len, ...); +TNT *new_tnt_pointer(size_t size); + /* RIGHT should be created by new_tnt_string or something alike. If RIGHT is NULL, NULL is returned. */ @@ -68,6 +94,15 @@ 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_cpa_and_free_all(void *element); void destroy_grammar(void *grammar, int flag); +/* convenient macro */ + +#define NEW_CPA(X, ARRAY, SIZE) do { \ + X = MYALLOC(cpa, 1); \ + X->array = ARRAY; \ + X->size = SIZE; \ + } while (0) + #endif |