-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbol.ml
65 lines (50 loc) · 1.11 KB
/
symbol.ml
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
module Token = struct
type t = Number of float
| Left
| Right
| Fact
| Cos
| Mult
| Plus
| Minus
| EOF
let to_string = function
| Number x -> x |> string_of_float
| Left -> "("
| Right -> ")"
| Fact -> "!"
| Cos -> "cos"
| Mult -> "*"
| Plus -> "+"
| Minus -> "-"
| EOF -> "$"
end
module Terminal = Token
module Nonterminal = struct
type t = E'
| E
| T
| F
| CA
| FA
| U
let follow =
let open Terminal in
function
| E' -> [EOF]
| E -> [Plus; Minus; Right; EOF]
| T -> [Plus; Minus; Right; EOF]
| F -> [Mult; Plus; Minus; Right; EOF]
| CA -> [Fact; Mult; Plus; Minus; Right; EOF]
| FA -> [Fact; Mult; Plus; Minus; Right; EOF]
| U -> [Fact; Mult; Plus; Minus; Right; EOF]
let to_string = function
| E' -> "Starting Symbol"
| E -> "Expression"
| T -> "Term"
| F -> "Factor"
| CA -> "Cosine Argument"
| FA -> "Factorial Argument"
| U -> "Unsigned Number"
end
type t = Term of Terminal.t | Nonterm of Nonterminal.t