Typechecking for basic language done
[hcoop/domtool2.git] / src / ast.sml
CommitLineData
42198578
AC
1(* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2006, Adam Chlipala
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*)
18
19(* Configuration language abstract syntax *)
20
21structure Ast = struct
22
23open DataStructures
24
25(* A description of a predicate on configuration block stacks *)
63920aa5 26datatype pred' =
42198578
AC
27 CRoot
28 (* The stack is empty. *)
29 | CConst of string
63920aa5
AC
30 (* The given pred name is on top of the stack. *)
31 | CPrefix of pred
32 (* Some prefix of the stack matches the pred. *)
33 | CNot of pred
34 (* The pred does not match. *)
35 | CAnd of pred * pred
36 (* Both preds match. *)
37withtype pred = pred' * position
42198578
AC
38
39datatype typ' =
40 TBase of string
41 (* Base type *)
42 | TList of typ
43 (* SML 'a list *)
44 | TArrow of typ * typ
45 (* SML -> *)
63920aa5 46 | TAction of pred * record * record
42198578 47 (* An action that:
63920aa5 48 * - Is valid in the given pred
42198578
AC
49 * - Expects an environment compatible with the first record
50 * - Modifies it according to the second record *)
27d9de59
AC
51
52 | TError
53 (* Marker that something already went wrong, so don't generate further
54 * error messages. *)
55 | TUnif of string * typ option ref
56 (* Unification variable to be determined during type-checking *)
42198578
AC
57withtype typ = typ' * position
58 and record = typ StringMap.map
59
60datatype exp' =
61 EInt of int
62 (* Constant integer *)
63 | EString of string
64 (* Constant string *)
65 | EList of exp list
66 (* Basic list constructor *)
67
27d9de59 68 | ELam of string * typ option * exp
42198578 69 (* Function abstraction *)
a22c187b
AC
70 | EVar of string
71 (* Variable bound by a function *)
42198578
AC
72 | EApp of exp * exp
73 (* Function application *)
74
75 | ESet of string * exp
76 (* Set an environment variable *)
63920aa5 77 | EGet of string * string * exp
a22c187b 78 (* Get an environment variable *)
42198578
AC
79 | ESeq of exp list
80 (* Monad sequencer; execute a number of commands in order *)
81 | ELocal of exp
82 (* Local execution; execute the action and then restore the previous
83 * environment. *)
84withtype exp = exp' * position
85
86
87end