From d4b7a0a25c2683c124ce8151c5ebf92e034491f4 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 27 Oct 2024 13:55:12 +0000 Subject: [PATCH] Revert "Use char instead of int for FSA rule input" This reverts commit eb22abfb1b6dbdf6dc702e3d9d99314cbbb22d7b. --- lib/fsa.c | 3 ++- lib/include/fsa.h | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/fsa.c b/lib/fsa.c index 9d73a88..a4611aa 100644 --- a/lib/fsa.c +++ b/lib/fsa.c @@ -47,10 +47,11 @@ int fsa_add_state(fsa_t *fsa) return fsa->count++; } -void fsa_add_rule(fsa_t *fsa, int from, int to, char input) +void fsa_add_rule(fsa_t *fsa, int from, int to, int input) { assert(fsa->count > from); assert(fsa->count > to); + assert(input < ALPHABET_SIZE); fsa_state_t *state = &fsa->states[from]; if (state->count >= state->capacity) { diff --git a/lib/include/fsa.h b/lib/include/fsa.h index 7eb474e..85ee342 100644 --- a/lib/include/fsa.h +++ b/lib/include/fsa.h @@ -8,9 +8,14 @@ #include +#define CHAR_COUNT 256 +#define ALPHABET_SIZE (CHAR_COUNT + 1) + +// Use one more than any valid char to represent empty string +#define EPSILON CHAR_COUNT + typedef struct { - int next; - char input; + int input, next; } fsa_rule_t; typedef struct { @@ -28,6 +33,6 @@ void fsa_init(fsa_t *fsa); void fsa_free(const fsa_t *fsa); int fsa_add_state(fsa_t *fsa); -void fsa_add_rule(fsa_t *fsa, int from, int to, char input); +void fsa_add_rule(fsa_t *fsa, int from, int to, int input); #endif