-- This is the file EXPr.ADB 7:38AM 10/11/95 -- It contains the body of packageexpr, which defines Exp, a type to -- implement SymbolicExpressions and all the subtypes needed for -- expressions. Constructors, Selectors and -- Testers are provided. The package expr.io defines put and get -- on these types. The package eval defines evaluation of expressions. package body expr is function MkConst(I : Integer) return Exp is begin return new ExpRec'(const, I); end MkConst; function MkVar(Name : Symbol) return Exp is begin return new ExpRec'(var, Name); end MkVar; function MkDef(Name : Symbol; E : Exp) return Exp is begin return new ExpRec'(def, Name, E); end MkDef; function MkSet(Name : Symbol; E : Exp) return Exp is begin return new ExpRec'(set, Name, E); end MkSet; function MkFcn(FnTyp : FcnType; Name : Symbol; Namelist : SymbolList; FcnBody : Exp) return Exp is begin return new ExpRec'(fcn, FnTyp, Name, NameList, FcnBody); end MkFcn; function MkSeq(EL : ExpList) return Exp is begin return new ExpRec'(seq, EL); end MkSeq; function MkApp(Op : Exp; ArgList : ExpList) return Exp is begin return new ExpRec'(app, Op, ArgList); end MkApp; function MkDummy(Msg : Symbol) return Exp is E : Exp; begin return new ExpRec'(done,Msg); end MkDummy; function MkEndparen(Msg : Symbol) return Exp is begin return new ExpRec'(endparen, Msg); end MkEndparen; -- selector functions function TypeOfExp(E: Exp) return ExpType is begin return E.etype; end TypeOfExp; function TypeOfFcn(E: Exp) return FcnType is begin return E.funtype; end TypeOfFcn; function ConstVal(C : Exp) return Integer is begin return C.value; end ConstVal; function VarName(Var : Exp) return Symbol is begin return Var.vname; end VarName; function DefName(Defn : Exp) return Symbol is begin return Defn.name; end DefName; function DefBody(Defn : Exp) return Exp is begin return Defn.expr; end DefBody; function SetName(SetExp : Exp) return Symbol is begin return SetExp.name; end SetName; function SetBody(SetExp : Exp) return Exp is begin return SetExp.expr; end SetBody; function FcnName(Fcn : Exp) return Symbol is begin return Fcn.fname; end FcnName; function FcnParams(Fcn : Exp) return SymbolList is begin return Fcn.params; end FcnParams; function FcnBody(Fcn : Exp) return Exp is begin return Fcn.fnbody; end FcnBody; function Seq(SeqExp : Exp) return ExpList is begin return SeqExp.list; end Seq; function AppOp(FunApp : Exp) return Exp is begin return FunApp.op; end AppOp; function AppArgs(FunApp : Exp) return ExpList is begin return FunApp.arglist; end AppArgs; -- tester functions function IsConst(E : Exp) return Boolean is begin return (E.etype = const); end IsConst; function IsVar(E : Exp) return Boolean is begin return (E.etype = var); end IsVar; function IsDef(E : Exp) return Boolean is begin return (E.etype = def); end IsDef; function IsSet(E : Exp) return Boolean is begin return (E.etype = set); end IsSet; function IsFcn(E : Exp) return Boolean is begin return (E.etype = fcn); end IsFcn; function IsSeq(E : Exp) return Boolean is begin return (E.etype = seq); end IsSeq; function IsApp(E : Exp) return Boolean is begin return (E.etype = app); end IsApp; function IsDummy(E : Exp) return Boolean is begin return (E.etype = done); end IsDummy; function IsEndparen(E : Exp) return Boolean is begin return (E.etype = endparen); end IsEndparen; end expr;