Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/compiler/Parse/ast/ast.sml
ViewVC logotype

Annotation of /sml/trunk/compiler/Parse/ast/ast.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4090 - (view) (download)

1 : dbm 3665 (* ast.sml *)
2 :     (* Syntax trees for bare ML *)
3 :     (* Copyright 1992 by AT&T Bell Laboratories *)
4 : monnier 16
5 :     (****************************************************************************
6 :     * PLEASE PROPAGATE ANY MODIFICATIONS TO THIS FILE *
7 :     * INTO PERV.SML AND SYSTEM.SIG *
8 :     ****************************************************************************)
9 :    
10 :     structure Ast : AST = struct
11 :    
12 :     open Symbol Fixity
13 :    
14 :     (* to mark positions in files *)
15 :     type srcpos = int (* character position from beginning of stream (base 0) *)
16 :     type region = srcpos * srcpos (* start and end position of region *)
17 :    
18 :     (* symbolic path (Modules.spath) *)
19 :     type path = symbol list
20 :     type 'a fixitem = {item: 'a, fixity: symbol option, region: region}
21 :    
22 :     type literal = IntInf.int
23 :    
24 :     datatype 'a sigConst
25 :     = NoSig
26 :     | Transparent of 'a
27 :     | Opaque of 'a
28 :    
29 :     (* EXPRESSIONS *)
30 :    
31 :     datatype exp
32 :     = VarExp of path (* variable *)
33 :     | FnExp of rule list (* abstraction *)
34 :     | FlatAppExp of exp fixitem list (* expressions before fixity parsing *)
35 :     | AppExp of {function:exp,argument:exp}
36 :     (* application *)
37 :     | CaseExp of{expr:exp,rules:rule list}
38 :     (* case expression *)
39 :     | LetExp of {dec:dec,expr:exp} (* let expression *)
40 :     | SeqExp of exp list (* sequence of expressions *)
41 :     | IntExp of literal (* integer *)
42 :     | WordExp of literal (* word literal *)
43 :     | RealExp of string (* floating point coded by its string *)
44 :     | StringExp of string (* string *)
45 :     | CharExp of string (* char *)
46 :     | RecordExp of (symbol * exp) list (* record *)
47 :     | ListExp of exp list (* [list,in,square,brackets] *)
48 :     | TupleExp of exp list (* tuple (derived form) *)
49 :     | SelectorExp of symbol (* selector of a record field *)
50 :     | ConstraintExp of {expr:exp,constraint:ty}
51 :     (* type constraint *)
52 :     | HandleExp of {expr:exp, rules:rule list}
53 :     (* exception handler *)
54 :     | RaiseExp of exp (* raise an exception *)
55 :     | IfExp of {test:exp, thenCase:exp, elseCase:exp}
56 :     (* if expression (derived form) *)
57 :     | AndalsoExp of exp * exp (* andalso (derived form) *)
58 :     | OrelseExp of exp * exp (* orelse (derived form) *)
59 :     | WhileExp of {test:exp,expr:exp}
60 :     (* while (derived form) *)
61 :     | MarkExp of exp * region (* mark an expression *)
62 :     | VectorExp of exp list (* vector *)
63 :    
64 :     (* RULE for case functions and exception handler *)
65 :     and rule = Rule of {pat:pat,exp:exp}
66 :    
67 :     (* PATTERN *)
68 : jhr 4090 and pat
69 :     = WildPat (* empty pattern *)
70 :     | VarPat of path (* variable pattern *)
71 :     | IntPat of literal (* integer *)
72 :     | WordPat of literal (* word literal *)
73 :     | StringPat of string (* string *)
74 :     | CharPat of string (* char *)
75 :     | RecordPat of {def:(symbol * pat) list, flexibility:bool}
76 :     (* record *)
77 :     | ListPat of pat list (* [list,in,square,brackets] *)
78 :     | TuplePat of pat list (* tuple *)
79 :     | FlatAppPat of pat fixitem list (* patterns before fixity parsing *)
80 :     | AppPat of {constr:pat,argument:pat} (* constructor application *)
81 :     | ConstraintPat of {pattern:pat,constraint:ty}
82 :     (* constraint *)
83 :     | LayeredPat of {varPat:pat,expPat:pat} (* as patterns *)
84 :     | MarkPat of pat * region (* mark a pattern *)
85 :     | VectorPat of pat list (* vector pattern *)
86 :     | OrPat of pat list (* or-pattern *)
87 : monnier 16
88 :     (* STRUCTURE EXPRESSION *)
89 :     and strexp = VarStr of path (* variable structure *)
90 :     | BaseStr of dec (* basic structure (struct...end) *)
91 :     | ConstrainedStr of strexp * sigexp sigConst (* signature constrained *)
92 :     | AppStr of path * (strexp * bool) list
93 :     (* application (external) *)
94 :     | AppStrI of path * (strexp * bool) list
95 :     (* application (internal) *)
96 :     | LetStr of dec * strexp (* let in structure *)
97 :     | MarkStr of strexp * region (* mark *)
98 :    
99 :     (* FUNCTOR EXPRESSION *)
100 :     and fctexp = VarFct of path * fsigexp sigConst (* functor variable *)
101 :     | BaseFct of { (* definition of a functor *)
102 :     params : (symbol option * sigexp) list,
103 :     body : strexp,
104 :     constraint : sigexp sigConst}
105 :     | LetFct of dec * fctexp
106 :     | AppFct of path * (strexp * bool) list * fsigexp sigConst
107 :     (* application *)
108 :     | MarkFct of fctexp * region (* mark *)
109 :    
110 :     (* WHERE SPEC *)
111 :     and wherespec = WhType of symbol list * tyvar list * ty
112 :     | WhStruct of symbol list * symbol list
113 :    
114 :     (* SIGNATURE EXPRESSION *)
115 :     and sigexp = VarSig of symbol (* signature variable *)
116 :     | AugSig of sigexp * wherespec list (* sig augmented with where specs *)
117 :     | BaseSig of spec list (* basic signature (sig...end) *)
118 :     | MarkSig of sigexp * region (* mark *)
119 :    
120 :     (* FUNCTOR SIGNATURE EXPRESSION *)
121 :     and fsigexp = VarFsig of symbol (* funsig variable *)
122 :     | BaseFsig of {param: (symbol option * sigexp) list, result:sigexp}
123 :     (* basic funsig *)
124 :     | MarkFsig of fsigexp * region (* mark *)
125 :    
126 :     (* SPECIFICATION FOR SIGNATURE DEFINITIONS *)
127 : dbm 3665 and spec = StrSpec of (symbol * sigexp * path option) list (* structure *)
128 :     | TycSpec of ((symbol * tyvar list * ty option) list * bool) (* type *)
129 :     | FctSpec of (symbol * fsigexp) list (* functor *)
130 :     | ValSpec of (symbol * ty) list (* value *)
131 : monnier 16 | DataSpec of {datatycs: db list, withtycs: tb list} (* datatype *)
132 : dbm 3665 | DataReplSpec of symbol * path (* datatype replication *)
133 :     | ExceSpec of (symbol * ty option) list (* exception *)
134 :     | ShareStrSpec of path list (* structure sharing *)
135 :     | ShareTycSpec of path list (* type sharing *)
136 :     | IncludeSpec of sigexp (* include specif *)
137 :     | MarkSpec of spec * region (* mark a spec *)
138 : monnier 16
139 :     (* DECLARATIONS (let and structure) *)
140 :     and dec = ValDec of (vb list * tyvar list) (* values *)
141 :     | ValrecDec of (rvb list * tyvar list) (* recursive values *)
142 :     | FunDec of (fb list * tyvar list) (* recurs functions *)
143 :     | TypeDec of tb list (* type dec *)
144 : dbm 3665 | DatatypeDec of {datatycs: db list, withtycs: tb list} (* datatype dec *)
145 :     | DataReplDec of symbol * path (* dt replication *)
146 :     | AbstypeDec of {abstycs: db list, withtycs: tb list, body: dec} (* abstract type *)
147 : monnier 16 | ExceptionDec of eb list (* exception *)
148 :     | StrDec of strb list (* structure *)
149 :     | AbsDec of strb list (* abstract struct *)
150 :     | FctDec of fctb list (* functor *)
151 :     | SigDec of sigb list (* signature *)
152 :     | FsigDec of fsigb list (* funsig *)
153 :     | LocalDec of dec * dec (* local dec *)
154 :     | SeqDec of dec list (* sequence of dec *)
155 :     | OpenDec of path list (* open structures *)
156 : dbm 3665 | OvldDec of symbol * ty * exp list (* overloading (internal) *)
157 : monnier 16 | FixDec of {fixity: fixity, ops: symbol list} (* fixity *)
158 : dbm 3665 | MarkDec of dec * region (* mark a dec *)
159 : monnier 16
160 :     (* VALUE BINDINGS *)
161 : monnier 109 and vb = Vb of {pat: pat, exp: exp, lazyp: bool}
162 : monnier 16 | MarkVb of vb * region
163 :    
164 :     (* RECURSIVE VALUE BINDINGS *)
165 : monnier 109 and rvb = Rvb of {var: symbol, fixity: (symbol * region) option,
166 :     exp: exp, resultty: ty option, lazyp: bool}
167 :     | MarkRvb of rvb * region
168 : monnier 16
169 :     (* RECURSIVE FUNCTIONS BINDINGS *)
170 : monnier 109 and fb = Fb of clause list * bool (* bool indicates whether lazy *)
171 : monnier 16 | MarkFb of fb * region
172 :    
173 :     (* CLAUSE: a definition for a single pattern in a function binding *)
174 :     and clause = Clause of {pats: pat fixitem list, resultty: ty option, exp:exp}
175 :    
176 :     (* TYPE BINDING *)
177 :     and tb = Tb of {tyc : symbol, def : ty, tyvars : tyvar list}
178 :     | MarkTb of tb * region
179 :    
180 :     (* DATATYPE BINDING *)
181 : dbm 3665 and db = Db of {tyc : symbol, tyvars : tyvar list,
182 :     rhs : (symbol * ty option) list, lazyp : bool}
183 : monnier 16 | MarkDb of db * region
184 :    
185 :     (* EXCEPTION BINDING *)
186 :     and eb = EbGen of {exn: symbol, etype: ty option} (* Exception definition *)
187 :     | EbDef of {exn: symbol, edef: path} (* defined by equality *)
188 :     | MarkEb of eb * region
189 :    
190 :     (* STRUCTURE BINDING *)
191 :     and strb = Strb of {name: symbol,def: strexp,constraint: sigexp sigConst}
192 :     | MarkStrb of strb * region
193 :    
194 :     (* FUNCTOR BINDING *)
195 :     and fctb = Fctb of {name: symbol,def: fctexp}
196 :     | MarkFctb of fctb * region
197 :    
198 :     (* SIGNATURE BINDING *)
199 :     and sigb = Sigb of {name: symbol,def: sigexp}
200 :     | MarkSigb of sigb * region
201 :    
202 :     (* FUNSIG BINDING *)
203 :     and fsigb = Fsigb of {name: symbol,def: fsigexp}
204 :     | MarkFsigb of fsigb * region
205 :    
206 :     (* TYPE VARIABLE *)
207 :     and tyvar = Tyv of symbol
208 :     | MarkTyv of tyvar * region
209 :    
210 :     (* TYPES *)
211 :     and ty
212 :     = VarTy of tyvar (* type variable *)
213 :     | ConTy of symbol list * ty list (* type constructor application *)
214 :     | RecordTy of (symbol * ty) list (* record *)
215 :     | TupleTy of ty list (* tuple *)
216 :     | MarkTy of ty * region (* mark type *)
217 :    
218 :     end (* structure Ast *)
219 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0