-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAST.fs
58 lines (50 loc) · 1.98 KB
/
AST.fs
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
module AST
open System
type Expression =
| Equals of left: Expression * right: Expression
| NotEquals of left: Expression * right: Expression
| Not of Expression
| Bigger of left: Expression * right: Expression
| Smaller of left: Expression * right: Expression
| Atomic of Atomic
| Nested of Expression
| Id of string
| And of left: Expression * right: Expression
| Or of left: Expression * right: Expression
| CollectionInit of Expression list
| CollectionGet of id: string * index: Expression
and Atomic =
| String of string
| Int of int
| Bool of bool
| Collection of Atomic list
with member l.IsEqual (r: Atomic) =
match (l, r) with
| (Bool l, Bool r) -> l = r
| (Int l, Int r) -> l = r
| (String l, String r) -> l = r
| _ -> raise <| Exception "exepected Bool expr for '=='"
member l.IsNotEqual (r: Atomic) =
match (l, r) with
| (Bool l, Bool r) -> l <> r
| (Int l, Int r) -> l <> r
| (String l, String r) -> l <> r
| _ -> raise <| Exception "exepected Bool expr for '!='"
member l.IsBigger (r: Atomic) =
match (l, r) with
| (Int l, Int r) -> l > r
| _ -> raise <| Exception "exepected Int expr for '>'"
member l.IsSmaller (r: Atomic) =
match (l, r) with
| (Int l, Int r) -> l < r
| _ -> raise <| Exception "exepected Int expr for '<'"
and Statement =
| Declaration of name: string * expr: Expression
| Assigment of name: string * expr: Expression
| If of predicate: Expression * _then: CodeBlock * _else: CodeBlock option
| Echo of Expression
| Expression of Expression
| CollectionSet of id: string * index: Expression * value: Expression
| CollectionAdd of id: string * value: Expression
| ForEach of id:string * alias: string * codeblock: CodeBlock
and CodeBlock = CodeBlock of Statement list