-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrnDrawTree.fs
52 lines (43 loc) · 1.89 KB
/
CrnDrawTree.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
(*
Date: XX.06.2023
Author:
*)
module CrnDrawTree
open CrnTypes
open DesignTrees
open DrawTrees
let speciesToTree (Species id) = Node(id, [])
let moduleToTree =
function
| Ld(s1, s2) -> Node("ld", [ speciesToTree s1; speciesToTree s2 ])
| Add(s1, s2, s3) -> Node("add", [ speciesToTree s1; speciesToTree s2; speciesToTree s3 ])
| Sub(s1, s2, s3) -> Node("sub", [ speciesToTree s1; speciesToTree s2; speciesToTree s3 ])
| Mul(s1, s2, s3) -> Node("mul", [ speciesToTree s1; speciesToTree s2; speciesToTree s3 ])
| Div(s1, s2, s3) -> Node("div", [ speciesToTree s1; speciesToTree s2; speciesToTree s3 ])
| Sqrt(s1, s2) -> Node("sqrt", [ speciesToTree s1; speciesToTree s2 ])
| Cmp(s1, s2) -> Node("cmp", [ speciesToTree s1; speciesToTree s2 ])
let exprToTree =
function
| [] -> failwith "Expression cannot be empty"
| Species s0 :: es -> List.fold (fun rest (Species s) -> Node("+", [ Node(s, []); rest ])) (Node(s0, [])) es
let ComputationcommandToTree =
function
| Mod(modu) -> moduleToTree modu
| Rxn(e1, e2, n) -> Node($"rxn: {n}", [ (exprToTree e1); exprToTree e2 ])
let conditionalCommandToTree =
function
| IfGT(cmds) -> Node("ifGT", List.map ComputationcommandToTree cmds)
| IfGE(cmds) -> Node("ifGE", List.map ComputationcommandToTree cmds)
| IfEQ(cmds) -> Node("ifEQ", List.map ComputationcommandToTree cmds)
| IfLT(cmds) -> Node("ifLT", List.map ComputationcommandToTree cmds)
| IfLE(cmds) -> Node("ifLE", List.map ComputationcommandToTree cmds)
let CommandsToTree =
function
| Comp(cmd) -> ComputationcommandToTree cmd
| Cond(con) -> conditionalCommandToTree con
let rootToTree =
function
| Conc(sp, n) -> Node("conc", [ speciesToTree sp; Node(n.ToString(), []) ])
| Step(cmds) -> Node("step", List.map CommandsToTree cmds)
let crnToTree (CRN(rootList)) =
Node("CRN", List.map rootToTree rootList)