structure Absyn = struct type symbol = Symbol.symbol type pos = Pos.T datatype var = SimpleVar of symbol * pos | FieldVar of var * symbol * pos | SubscriptVar of var * exp * pos and exp = VarExp of var | NilExp | IntExp of int | StringExp of string * pos | CallExp of {func: symbol, args: exp list, pos: pos} | OpExp of {left: exp, oper: oper, right: exp, pos: pos} | ArrayExp of {typ: symbol, size: exp, init: exp, pos: pos} | RecordExp of {fields: (symbol * exp * pos) list, typ: symbol, pos: pos} | SeqExp of (exp * pos) list | AssignExp of {var: var, exp: exp, pos: pos} | IfExp of {test: exp, then': exp, else': exp option, pos: pos} | WhileExp of {test: exp, body: exp, pos: pos} | ForExp of {var: symbol, escape: bool ref, lo: exp, hi: exp, body: exp, pos: pos} | BreakExp of pos | LetExp of {decs: dec list, body: exp, pos: pos} and dec = FunctionDec of fundec list | VarDec of {name: symbol, escape: bool ref, typ: (symbol * pos) option, init: exp, pos: pos} | TypeDec of {name: symbol, ty: ty, pos: pos} list and ty = NameTy of symbol * pos | RecordTy of tyField list | ArrayTy of symbol * pos and oper = PlusOp | MinusOp | TimesOp | DivideOp | EqOp | NeqOp | LtOp | LeOp | GtOp | GeOp | AndOp | OrOp (* to be eliminated *) withtype tyField = {name: symbol, typ: symbol, pos: pos} and param = {name: symbol, escape: bool ref, typ: symbol, pos: pos} and fundec = {name: symbol, params: param list, result: (symbol * pos) option, body: exp, pos: pos} (* opname: generate names for operators *) val opname: oper -> string = fn PlusOp => "PlusOp" | MinusOp => "MinusOp" | TimesOp => "TimesOp" | DivideOp => "DivideOp" | EqOp => "EqOp" | NeqOp => "NeqOp" | LtOp => "LtOp" | LeOp => "LeOp" | GtOp => "GtOp" | GeOp => "GeOp" | AndOp => "AndOp" | OrOp => "OrOp" fun exp2str (t: exp): string = "..." fun var2pos (v: var): pos = case v of SimpleVar (_, pos) => pos | FieldVar (_, _, pos) => pos | SubscriptVar (_, _, pos) => pos fun mkTyField (name: symbol, tyid: symbol, pos: pos) = {name= name, typ= tyid, pos= pos} fun mkTyDec (name, ty, pos) = {name= name, ty= ty, pos= pos} fun mkFieldVar (v: var, name: symbol, pos: pos): var = FieldVar (v, name, Pos.union (var2pos v, pos)) fun mkSubscriptVar (v: var, e: exp, pos: pos): var = SubscriptVar (v, e, Pos.union (var2pos v, pos)) fun mkNegExp (e: exp, pos: pos): exp = OpExp {oper= MinusOp, left=IntExp 0, right=e, pos= pos} fun mkBinOp (oper: oper) ((e1, p1): exp * pos, (e2, p2): exp * pos) : exp * pos = let val pos = Pos.union (p1, p2) in (OpExp {oper= oper, left=e1, right=e2, pos= pos}, pos) end fun mkNegOp (p0: pos) (e: exp, p: pos): exp * pos = let val pos = Pos.union (p0, p) in (OpExp {oper= MinusOp, left=IntExp 0, right=e, pos= pos}, pos) end fun mkVarDec (name, otp, e, pos): dec = VarDec {name= name, escape= ref false, typ= otp, init= e, pos= pos} fun mkParam (name: symbol, tyid: symbol, pos: pos) = {name= name, escape = ref false, typ= tyid, pos= pos} fun mkFunctionDec (name, params, otp, body, pos) = {name= name, params= params, result= otp, body= body, pos= pos} end