34 lines
524 B
C
34 lines
524 B
C
/*
|
|
* Copyright (c) Camden Dixie O'Brien
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
#ifndef FSA_H
|
|
#define FSA_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
int next;
|
|
char input;
|
|
} 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, char input);
|
|
|
|
#endif
|