-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlcParserAux.sml
39 lines (35 loc) · 1.12 KB
/
PlcParserAux.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
(* Plc Parser Aux *)
(* Creat the body of a function expression. *)
fun makeFunAux (n:int, xs:(plcType * string) list, e:expr): expr =
case xs of
[] => e
| (t,x)::r => Let(x, Item(n, Var "$list"), makeFunAux ((n +1), r, e) );
(* Create the list of arguments of a function. *)
fun makeType (args:(plcType * string) list):plcType = ListT (List.map (fn (x,y) => x) args);
(* Create a function expression. *)
fun makeFun (f: string, xs: (plcType * string) list, rt: plcType, e1: expr, e2: expr): expr =
case xs of
[] => Letrec(f, ListT [], "()", rt, e1, e2)
| (t,x)::[] => Letrec(f, t, x, rt, e1, e2)
| _ =>
let
val t = makeType xs
val e1' = makeFunAux (1, xs, e1)
in
Letrec(f, t, "$list", rt, e1', e2)
end;
(* Create a Anonymus function expression. *)
fun makeAnon (xs:(plcType * string) list, e:expr):expr =
case xs of
[] => Anon(ListT [], "()", e)
| (t,x)::[] => Anon(t,x,e)
| _ =>
let
val t = makeType xs
in
let
val e' = makeFunAux (1, xs, e)
in
Anon(t,"$list",e')
end
end;