home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / parse / ast.sml next >
Encoding:
Text File  |  1993-01-27  |  7.2 KB  |  200 lines

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