-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.mli
164 lines (136 loc) · 6.24 KB
/
syntax.mli
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
(******************************************************************************)
(* The Frenetic Project *)
(* [email protected] *)
(******************************************************************************)
(* Licensed to the Frenetic Project by one or more contributors. See the *)
(* NOTICE file distributed with this work for additional information *)
(* regarding copyright and ownership. The Frenetic Project licenses this *)
(* file to you under the following license. *)
(* *)
(* Redistribution and use in source and binary forms, with or without *)
(* modification, are permitted provided the following conditions are met: *)
(* - Redistributions of source code must retain the above copyright *)
(* notice, this list of conditions and the following disclaimer. *)
(* - Redistributions in binary form must reproduce the above copyright *)
(* notice, this list of conditions and the following disclaimer in *)
(* the documentation or other materials provided with the distribution. *)
(* - The names of the copyright holds and contributors may not be used to *)
(* endorse or promote products derived from this work without specific *)
(* prior written permission. *)
(* *)
(* Unless required by applicable law or agreed to in writing, software *)
(* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT *)
(* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the *)
(* LICENSE file distributed with this work for specific language governing *)
(* permissions and limitations under the License. *)
(******************************************************************************)
(* /src/compiler/syntax.ml *)
(* Frenetic abstract syntax interface *)
(* $Id$ *)
(******************************************************************************)
module StrSet : Set.S with type elt = string
(** {2 Frenetic Abstract Syntax} *)
type typ =
(* base types *)
| TUnit (* unit *)
| TBool (* booleans *)
| TInteger (* integers *)
| TChar (* chars *)
| TString (* strings *)
(* products and sums *)
| TProduct of typ * typ (* products *)
| TData of typ list * Id.t (* data types *)
(* function types *)
| TFunction of typ * typ
| TVar of Id.t (* variables *)
(** Type abstract syntax *)
and scheme = Scheme of Id.Set.t * typ
(** Type schemes abstract syntax *)
and exp =
(* lambda calculus *)
| EVar of Info.t * Id.t
| EApp of Info.t * exp * exp
| EFun of Info.t * param * exp
| ECond of Info.t * exp * exp * exp
| ELet of Info.t * bind * exp
| EAsc of Info.t * exp * typ
| EOver of Info.t * op * exp list
(* with products, case *)
| EPair of Info.t * exp * exp
| ECase of Info.t * exp * (pattern * exp) list
(* unit, ints, characters, strings, bools *)
| EUnit of Info.t
| EInteger of Info.t * int
| EChar of Info.t * char
| EString of Info.t * string
| EBool of Info.t * bool
(** Expression abstract syntax *)
and op =
| OSemi
| OEqual
| OMinus
| OLt
| OLeq
| OGt
| OGeq
(** Overloaded operator abstract syntax *)
and param = Param of Info.t * pattern * typ option
(** Parameter abstract syntax *)
and bind = Bind of Info.t * pattern * typ option * exp
(** Binding abstract syntax *)
and pattern =
| PWild of Info.t
| PUnit of Info.t
| PBool of Info.t * bool
| PInteger of Info.t * int
| PString of Info.t * string
| PVar of Info.t * Id.t * typ option
| PData of Info.t * Id.t * pattern option
| PPair of Info.t * pattern * pattern
(** Pattern abstract syntax *)
type decl =
| DLet of Info.t * bind
| DType of Info.t * Id.t list * Id.t * (Id.t * typ option) list
(** Declaration abstract syntax *)
type modl = Modl of Info.t * Id.t * decl list
(** Module abstract syntax *)
val (^>) : typ -> typ -> typ
(** [s1 ^> s2] is the function typ from [s1] to [s2]. *)
val (^*) : typ -> typ -> typ
(** [s1 ^* s2] is the product typ between [s1] and [s2]. *)
val info_of_exp : exp -> Info.t
(** [info_of_exp e] returns the parsing info associated to expression [e]. *)
val info_of_pattern : pattern -> Info.t
(** [info_of_pat p] returns the parsing info associated to pattern [p]. *)
val info_of_module : modl -> Info.t
(** [info_of_module m] returns the parsing info associated to module [m]. *)
val info_of_decl : decl -> Info.t
(** [info_of_decl d] returns the parsing info associated to declaration [d]. *)
val id_of_module : modl -> Id.t
(** [id_of_module m] returns the name of module [m]. *)
val pattern_of_param : param -> pattern
(** [pattern_of_param p] extracts a pattern from parameter [p]. *)
val pat_of_binding : bind -> pattern
(** [pat_of_binding b] returns the name of the variable bound in [b]. *)
val exp_of_binding : bind -> exp
(** [exp_op_binding p] returns the expression of binding [b]. *)
(* ------ constructors ----- *)
val mk_unit : Info.t -> exp
val mk_int : Info.t -> int -> exp
val mk_string : Info.t -> string -> exp
val mk_var : Id.t -> exp
val mk_fun : Info.t -> Id.t -> typ option -> exp -> exp
val mk_multi_fun : Info.t -> param list -> exp -> exp
val mk_app : Info.t -> exp -> exp -> exp
val mk_app3 : Info.t -> exp -> exp -> exp -> exp
val mk_app4 : Info.t -> exp -> exp -> exp -> exp -> exp
val mk_over : Info.t -> op -> exp list -> exp
val mk_let : Info.t -> Id.t -> typ -> exp -> exp -> exp
val mk_asc : Info.t -> exp -> typ -> exp
val mk_if : Info.t -> exp -> exp -> exp -> exp
val mk_bin_op : Info.t -> exp -> exp -> exp -> exp
val mk_tern_op : Info.t -> exp -> exp -> exp -> exp -> exp
val bv : pattern -> Id.Set.t
val ftv : typ -> Id.Set.t
val fv : exp -> Id.Set.t
val ftv_exp : exp -> Id.Set.t