<> <> <> DIRECTORY MathRules USING [AtomBoxProc, AtomPaintProc, CompoundBoxProc, CompositionProc, AtomToRopeProc, Size], MathBox USING [BOX], MathTypes USING [Style, AtomValue], ImagerFont USING [Extents], Vector USING [VEC], Rope USING [ROPE]; MathExpr: CEDAR DEFINITIONS ~ BEGIN <> ROPE: TYPE ~ Rope.ROPE; VEC: TYPE ~ Vector.VEC; BOX: TYPE ~ MathBox.BOX; Style: TYPE ~ MathTypes.Style; AtomValue: TYPE ~ MathTypes.AtomValue; AtomBoxProc: TYPE ~ MathRules.AtomBoxProc; AtomPaintProc: TYPE ~ MathRules.AtomPaintProc; CompoundBoxProc: TYPE ~ MathRules.CompoundBoxProc; CompositionProc: TYPE ~ MathRules.CompositionProc; AtomToRopeProc: TYPE ~ MathRules.AtomToRopeProc; Size: TYPE ~ MathRules.Size; <<>> <<>> <> <<>> <> EXPR: TYPE ~ REF MathExprRep; -- external abstract type MathExprRep: TYPE; -- internal concrete rep AtomEXPR: TYPE ~ REF AtomExprRep; -- abstract AtomExprRep: TYPE; -- concrete CompoundEXPR: TYPE ~ REF CompoundExprRep; -- abstract CompoundExprRep: TYPE; -- concrete MatrixEXPR: TYPE ~ REF MatrixExprRep; -- abstract MatrixExprRep: TYPE; -- concrete ExprFlavors: TYPE ~ {atom, compound, matrix}; MatrixFlavor: TYPE ~ RECORD [ class: ATOM -- type of matrix expr, e.g. matrix or determinant ]; TaggedMathExpr: TYPE ~ RECORD [ id: ATOM, expression: EXPR ]; <> AtomFlavor: TYPE ~ {symbol, argument, placeholder}; AtomClass: TYPE ~ REF AtomClassRep; AtomClassRep: TYPE ~ RECORD [ name: ATOM, -- class identifier, e.g. $integer flavor: AtomFlavor, -- type of atom: symbol, argument, placeholder style: Style, -- font info boxRule: MathRules.AtomBoxProc, -- returns info about atom size paintRule: MathRules.AtomPaintProc, -- paints atom onto imager context cvtRope: MathRules.AtomToRopeProc -- returns value as rope ]; CompoundClass: TYPE ~ REF CompoundClassRep; CompoundClassRep: TYPE ~ RECORD [ name: ATOM, -- class identifier, e.g. $product description: ROPE, -- for menu buttons, etc. to describe how expr looks, e.g. "a + b" arguments: LIST OF Argument, symbols: LIST OF Symbol, boxRule: MathRules.CompoundBoxProc, compBox: MathRules.CompositionProc, cvtAS: ROPE _ NIL -- conversion specification to Dennis Arnon's AlgebraSystem ]; <> <<>> Argument: TYPE ~ RECORD [ name: ATOM, -- unique (within enclosing class) identifier for argument aliases: LIST OF ATOM, -- aliases for name using convention $aliasFoo, $aliasBar size: Size -- relative sizing information (big, script, etc.) ]; Symbol: TYPE ~ RECORD[ name: ATOM, -- unique (within enclosing class) identifier for symbol aliases: LIST OF ATOM, -- aliases for name using convention $aliasFoo, $aliasBar size: Size, -- relative sizing information (big, script, etc.) value: EXPR -- a symbol is an expression ]; <> <> <<>> MakeArgument: PROC[name: ATOM, aliases: LIST OF ATOM, size: Size] RETURNS[Argument]; <> MakeSymbol: PROC[name: ATOM, aliases: LIST OF ATOM, size: Size, value: EXPR] RETURNS[Symbol]; <> MakeAtomClass: PROC[name: ATOM, flavor: AtomFlavor, style: Style, boxRule: AtomBoxProc, paintRule: AtomPaintProc, cvtRope: AtomToRopeProc] RETURNS[AtomClass]; <> MakeCompoundClass: PROC[name: ATOM, description: ROPE, args: LIST OF Argument, syms: LIST OF Symbol, boxRule: CompoundBoxProc, compBox: CompositionProc, cvtAS: ROPE _ NIL] RETURNS[CompoundClass]; <> <<>> MakeAtomChar: PROC[c: CHAR] RETURNS[AtomValue]; <> MakeAtomRope: PROC[r: ROPE] RETURNS[AtomValue]; <> <<>> MakeAtomBox: PROC[b: ImagerFont.Extents] RETURNS[AtomValue]; <> MakeAtomOther: PROC[other: REF ANY] RETURNS[AtomValue]; <> <> MakeAtomicExpr: PROC[class: ATOM, value: AtomValue] RETURNS[EXPR]; <> << SIGNALS badAtomClass if class is unrecognized>> MakeCompoundExpr: PROC[class: ATOM, args: LIST OF TaggedMathExpr] RETURNS[EXPR]; <> << SIGNALS badCompoundClass if class is unrecognized>> << SIGNALS badExprs if exprs has the wrong number or wrong type of elements>> <<>> MakeMatrixExpr: PROC[flavor: MatrixFlavor, nRows, nCols: NAT, elements: LIST OF TaggedMathExpr, openSym, closeSym, space: EXPR] RETURNS[EXPR]; <> << SIGNALS badMatrixSize if nRows or nCols is invalid>> << SIGNALS badMatrix if rows has the wrong number or wrong type of elements>> <<>> <<>> <<>> <> <<>> GetType: PROC[expr: EXPR] RETURNS[ExprFlavors]; <> << Returns compound if expr is a CompoundEXPR>> <<>> GetAtomClass: PROC[expr: AtomEXPR] RETURNS[AtomClass]; <> <<>> GetAtomExpr: PROC[expr: EXPR] RETURNS[AtomEXPR]; <> << Otherwise SIGNALS wrongExprType>> GetValue: PROC[expr: AtomEXPR] RETURNS[AtomValue]; <> <<>> GetCompoundClass: PROC[expr: CompoundEXPR] RETURNS[CompoundClass]; <> <<>> GetCompoundExpr: PROC[expr: EXPR] RETURNS[CompoundEXPR]; <> << Otherwise SIGNALS wrongExprType>> <<>> GetMatrixExpr: PROC[expr: EXPR] RETURNS[MatrixEXPR]; <> << Otherwise SIGNALS wrongExprType>> GetSubExprs: PROC[expr: CompoundEXPR] RETURNS[LIST OF TaggedMathExpr]; <> <<>> GetMatrixElements: PROC[expr: MatrixEXPR] RETURNS[LIST OF TaggedMathExpr]; <> <<>> GetMatrixSize: PROC[expr: MatrixEXPR] RETURNS[NAT, NAT]; <> <<>> GetMatrixFlavor: PROC[expr: MatrixEXPR] RETURNS[MatrixFlavor]; <> <<>> GetMatrixOpenSym: PROC[expr: MatrixEXPR] RETURNS[EXPR]; <> GetMatrixCloseSym: PROC[expr: MatrixEXPR] RETURNS[EXPR]; <> <<>> GetMatrixSpace: PROC[expr: MatrixEXPR] RETURNS[EXPR]; <> <<>> <<>> <<>> <> GetTaggedExpr: PROC[tag: ATOM, exprs: LIST OF TaggedMathExpr] RETURNS[TaggedMathExpr]; <> << SIGNALS exprNotFound if no association exists.>> <<>> <<>> <> badAtomClass: ERROR; badCompoundClass: ERROR; badExprs: ERROR[reason: ATOM]; exprNotFound: ERROR; wrongExprType: ERROR; invalidReplacement: ERROR; <<>> END.