forked from codeon/cmlex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automata.sml
56 lines (47 loc) · 1.67 KB
/
automata.sml
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
structure SymbolSet = SplaySet (structure Elem = IntOrdered)
structure SymbolDict = SplayDict (structure Key = IntOrdered)
structure StringSet = SplaySet (structure Elem = StringOrdered)
structure StringDict = SplayDict (structure Key = StringOrdered)
structure Automata =
struct
type symbol = int
type state = int
type ('a, 'b) nfa =
(state * 'a) list (* initial states *)
*
(state * 'b) list (* final states *)
*
(state list SymbolDict.dict * state list) array
type ('a, 'b) dfa =
int (* number of states *)
*
(state * 'a) list (* initial states *)
*
(state * 'b) list (* final states *)
*
state SymbolDict.dict list
type automaton =
int (* total states *)
*
int (* initial state *)
*
int (* last final-sink state *)
*
int (* last final state *)
*
string array (* final states *)
*
int array array (* transition function *)
*
int array (* end-of-stream transition function *)
type lexer =
string StringDict.dict (* functor name *)
*
int (* alphabet size *)
*
string list (* type arguments, sorted *)
*
(string * string) list (* action arguments *)
*
(string * string * automaton) list (* lexing functions *)
end