39 lines
1.2 KiB
C
39 lines
1.2 KiB
C
#ifndef SLEX_REGEX_H
|
|
#define SLEX_REGEX_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
// Represents an NFA state
|
|
typedef struct NFAState {
|
|
int id;
|
|
bool is_epsilon;
|
|
bool char_set[256];
|
|
struct NFAState* edge1;
|
|
struct NFAState* edge2;
|
|
int accept_rule_index; // -1 if not accepting, >= 0 for rule index (highest priority is lowest index)
|
|
} NFAState;
|
|
|
|
// Represents an NFA fragment (start and accept states)
|
|
typedef struct NFAFragment {
|
|
NFAState* start;
|
|
NFAState* accept;
|
|
} NFAFragment;
|
|
|
|
// Represents a DFA state
|
|
typedef struct DFAState {
|
|
int id;
|
|
int* nfa_states; // Sorted list of NFA state IDs that make up this DFA state
|
|
int nfa_state_count;
|
|
int transitions[256]; // DFA state transitions for each character (-1 if no transition)
|
|
int accept_rule_index; // -1 if not accepting, >= 0 if accepting (stores rule index)
|
|
} DFAState;
|
|
|
|
// Compiles a set of regular expression patterns into a minimized/complete DFA
|
|
DFAState* slex_compile_regexes(char** patterns, int pattern_count, int* dfa_state_count_out);
|
|
|
|
// Frees all DFA states allocated by slex_compile_regexes
|
|
void slex_free_dfa(DFAState* dfa_states, int dfa_state_count);
|
|
|
|
#endif
|