Debian Codegraph @

lib/mllpt-lib/ml-lpt/ml-antlr/BackEnds/SML/abs.sml

raw
1 (* abs.sml
2 *
3 * COPYRIGHT (c) 2015 The Fellowship of SML/NJ (http://www.smlnj.org)
4 * All rights reserved.
5 *)
6
7 structure MLABS =
8 struct
9 type atom = Atom.atom
10 datatype raw_ml = Raw of ml_token list
11
12 and ml_token = Tok of string
13
14 datatype cmp_op = LT | GT | EQ | LEQ | GEQ
15 datatype bool_op = AND | OR
16
17 datatype ml_file
18 = OBJECT of ml_object
19
20 and ml_object
21 = DECL of ml_decl list
22 | STRUCTURE of ml_signature option * ml_structure
23 | LOCAL of ml_object * ml_object
24
25 and ml_decl
26 = D_VAL of (ml_pat * ml_exp) list
27 | D_FUN of ml_fundecl list
28 | D_TYPE of ml_type_binding
29 | D_ABS_DATATYPE of ml_datatype_binding * ml_type_binding option
30 (* datatype $1 withtype $2*)
31 | D_ABS_TYPE of ml_datatype_binding * ml_type_binding option * ml_decl list
32 (* abstype $1 withtype $2 with $3 end *)
33 (* | SD_LOCAL of ()
34 | SD_OPEN of ()
35 | SD_OPERATOR of ()
36 *)
37
38 and ml_fundecl = FUN of (ml_fun_heading * ml_type option * ml_exp) list (* none-empty list *)
39
40 and ml_type_binding
41 = TypeBind of (typevar list * ml_type) list (* none-empty *)
42
43 and ml_datatype_binding
44 = DatatypeBind of (typevar list * (id * ml_type option) list (* none-empty*)) list (* none-empty *)
45
46 and ml_fun_heading
47 = FUNHEAD of atom * ml_pat list (* none-empty *)
48
49 and ml_type
50 (*ml_type::= Type_Var | Type_Var_List Compound_Ident | Type "*" L(Type , "*") | Type "->" Type | "{" O_List( Label ":" Type ) "}" | "(" Type ")". *)
51 = T_VAR of typevar
52 | T_TUPLE of ml_type list (* NoneEmptyList *) (* t1 * t2 * .. *)
53 | T_FUN of ml_type * ml_type (* t1-> t2 *)
54 | T_RECORD of (label * ml_type) list
55 | T_PAREN of ml_type
56
57 and ml_signature (*signature*)
58 (* Signature::= "sig" Specification "end" | Ident.*)
59 = SG of ml_specification (* fix this *)
60
61 and ml_specification
62 = SP_EMPTY (* fix this *)
63 (*Specification::= Empty | value_spec | various_type_spec | exception_spec | structure_spec | other_spec | inclusion | Specification O(";") Specification. *)
64
65 and ml_structure (*structure*)
66 = ST_STRUCT of ml_object (* struct $1 end *)
67 (* Structure::= "struct" Object_Declaration "end" | Compound_Ident | Functor_Application | Ident "(" Object_Declaration ")" | "let" Object_Declaration "in" Structure "end".*)
68
69 (* a subset of ML expressions and patterns *)
70 and ml_exp
71 = ML_Var of string
72 | ML_Int of IntInf.int
73 | ML_Cmp of (cmp_op * ml_exp * ml_exp)
74 | ML_Bool of (bool_op * ml_exp * ml_exp)
75 | ML_Case of ml_exp * (ml_pat * ml_exp) list
76 | ML_If of ml_exp * ml_exp * ml_exp
77 | ML_App of (string * ml_exp list)
78 | ML_Let of (string * ml_exp * ml_exp)
79 (* a group of mutually-recursive functions *)
80 | ML_Funs of (string * string list * ml_exp) list * ml_exp
81 | ML_Seq of ml_exp list
82 | ML_Tuple of ml_exp list
83 | ML_List of ml_exp list
84 | ML_RefGet of ml_exp
85 | ML_RefPut of ml_exp * ml_exp
86 | ML_Handle of ml_exp * (ml_pat * ml_exp) list
87 | ML_Raw of ml_token list
88 (* the following added by Chunyan *)
89 | ML_TypeExp of ml_exp * ml_type
90
91 and ml_pat
92 = ML_Wild
93 | ML_VarPat of string
94 | ML_IntPat of IntInf.int
95 | ML_ConPat of string * ml_pat list
96 | ML_TupPat of ml_pat list
97 (* the following added by Chunyan *)
98 | ML_TypePat of ml_pat * ml_type
99 | ML_ListPat of ml_pat list
100
101 (*
102 and pattern
103 (* Pattern::= Atomic_Pattern | Compound_Name Atomic_Pattern | Pattern infix_constructor Pattern | Pattern ":" ml_type | Name O(":" ml_type) "as" Pattern. *)
104 = P_ATOM of atomic_pattern
105 | P_TYPE of pattern * ml_type
106 (* more *)
107 and atomic_pattern
108 = AP_NULL (* "_" *)
109 | AP_COMPNAME of id
110 (* | P_CONST why?? *)
111 | AP_TUPLE of pattern list
112 | AP_LIST of pattern list
113 | AP_RECORD of (label * pattern) list
114 (* more? *)
115
116 and exp
117 (* # Expression::= Infix_Expression | Expression ":" ml_type | Expression boolean_operator Expression | Expression "handle" Match | "raise" Expression | selection| loop | "fn" Match. *)
118 (* atomic expressions *)
119 = E_COMPNAME of atom
120 | E_CONST of const
121 | E_TUPLE of exp list
122 | E_LIST of exp list (* NoneEmptyList *)
123 | E_RECORD of (label * exp) list
124 | E_STMT of exp list (* NoneEmptyList *) (* e1; e2;... *)
125 | E_LET of decl * exp list (* NoneEmptyList *)
126 (* *)
127 | E_TYPE of exp * ml_type
128 | E_APPLY of exp list (* NoneEmptyList *)
129 | E_BOOLEAN of exp * boolop * exp
130 | E_HANDLE of exp * match
131 | E_RAISE of exp
132 (*
133 | E_SELECTION of selection
134 | E_LOOP of loop
135 *)
136 | E_FN of match
137 and const
138 = C_INT of int
139 | C_REAL of real
140 | C_STRING of string
141 (* ... *)
142
143 and boolop
144 = B_AND
145 | B_OR
146 *)
147 withtype label = atom
148 and id = atom
149 and typevar = atom (* fix this *)
150 and match = (ml_pat * ml_exp) list (* NoneEmptyList *)
151
152 end