summaryrefslogtreecommitdiff
path: root/src/grammar.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-11 09:58:43 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-11 09:58:43 +0800
commit91016bd3855375796fd1eabd501ebc12491f2655 (patch)
treec4a608966b686c9639a90b92c31c00632532fac8 /src/grammar.c
parent949888ad5d0cd0f9f9a87f9938a632b3e32df051 (diff)
Add the framework for character classes.
Now we have the potential to recognize character classes. But the most important task for us now is to experiment with ((B)RN)GLR algorithms, so we leave the character classes at the present state for a moment.
Diffstat (limited to 'src/grammar.c')
-rw-r--r--src/grammar.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/grammar.c b/src/grammar.c
index 4052510..508c8d8 100644
--- a/src/grammar.c
+++ b/src/grammar.c
@@ -104,14 +104,14 @@ new_tnt(int type, ...)
}
Rule *
-new_rule(NT left, List *right)
+new_rule(NT left, const List * const right)
{
if (!right) return NULL;
Rule *rule = MYALLOC(Rule, 1);
rule->left = left;
- rule->right = right;
+ rule->right = (List *) right;
return rule;
}
@@ -124,10 +124,10 @@ new_grammar()
}
/* We classify the rules into different rule groups. */
-unsigned char
-build_grammar(Grammar *g, List *rules, List *names)
+BOOL
+build_grammar(Grammar *g, const List *rules, const List * const names)
{
- g->names = names;
+ g->names = (List *) names;
NUM len = list_length(names);
NUM rule_len = list_length(rules);
@@ -246,11 +246,12 @@ print_rule(void *r)
}
NUM
-find_in_cpa_list(NUM *string, NUM size, List *list)
+find_in_cpa_list(const NUM * const restrict string, NUM size,
+ const List * const restrict list)
{
NUM len = list_length(list), index = 0;
- unsigned char foundp = 0;
+ BOOL foundp = 0;
for (; !foundp && index < len;) {
cpa *cpap = list_nth(list, index);
@@ -304,7 +305,7 @@ print_name(void *element)
/* REVIEW: Print the names of non-terminals out, instead of printing
the numbers? */
void
-print_grammar(Grammar *g)
+print_grammar(const Grammar * const g)
{
printf("Printing a grammar:\n");
map_list_between(g->names, print_name, print_sep);