/* * Copyright (c) Camden Dixie O'Brien * SPDX-License-Identifier: AGPL-3.0-only */ #ifndef FSA_H #define FSA_H #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 input, next; } fsa_rule_t; typedef struct { bool final; int count, capacity; fsa_rule_t *rules; } fsa_state_t; typedef struct { int count, capacity, initial; fsa_state_t *states; } fsa_t; 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, int input); #endif