-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomata.h
More file actions
101 lines (71 loc) · 1.57 KB
/
automata.h
File metadata and controls
101 lines (71 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef LEX_AUTOMATA
#define LEX_AUTOMATA
#include<stdlib.h>
#include<stdbool.h>
/* edge */
struct fsm;
struct edge {
char c;
struct fsm *dest;
bool owner;
};
struct edge *
edge_create(struct fsm *dest, char c, bool owner);
/* fsm */
struct fsm {
bool accepting;
size_t nedges;
struct edge **edges;
};
struct fsm *
fsm_create(bool accepting);
struct fsmlist;
struct fsm *
fsm_fromstring(char *regex, struct fsmlist *);
void
fsm_destroy(struct fsm *);
void
fsm_addedge(struct fsm *, struct edge *);
struct fsm *
fsm_sim(struct fsm *, char);
void
fsm_print(struct fsm *);
struct fsmset {
struct fsm **arr;
size_t len;
};
/* fsmlist */
struct fsmlist {
char *name;
struct fsm *s;
struct fsmlist *next;
};
void
fsmlist_destroy(struct fsmlist *);
struct fsm *
fsmlist_findfsm(struct fsmlist *, char *name);
struct fsmlist *
fsmlist_append(struct fsmlist *, char *, struct fsm *);
struct findresult {
char *fsm;
unsigned long len;
};
void
findresult_destroy(struct findresult *r);
/* fsmlist_findnext: simulates the fsms with the input until it can determine
* the highest-ranking, next match. if no match is found, returns a findresult
* with fsm == NULL and len set to the number of chars scanned. l is invariant */
struct findresult *
fsmlist_findnext(struct fsmlist *l, char *input);
/* automata */
void
automata_concat(struct fsm *, struct fsm *, bool);
struct fsm *
automata_union(struct fsm *, struct fsm *);
struct fsm *
automata_closure(struct fsm *, char);
struct fsm *
automata_class(char *);
struct fsm *
automata_id(char *id, struct fsmlist *l);
#endif