DIRECTORY Rope USING [ROPE]; RobotEvaluator: CEDAR DEFINITIONS ~ { UnOp: TYPE ~ REF UnOpRec; BinOp: TYPE ~ REF BinOpRec; TrinOp: TYPE ~ REF TrinOpRec; UnOpRec: PUBLIC TYPE ~ PROC [a: INTEGER] RETURNS [z: INTEGER]; BinOpRec: PUBLIC TYPE ~ PROC [a,b: INTEGER] RETURNS [z: INTEGER]; TrinOpRec: PUBLIC TYPE ~ PROC [a,b,c: INTEGER] RETURNS [z: INTEGER]; Value: TYPE ~ REF ValueRec; ValueRec: PUBLIC TYPE ~ RECORD [ type: ValueType _ unassigned, value: INTEGER _ 0, --Only used if type=integer, or type=symbolRef fcn: REF ANY _ NIL, --Only used if type IN {unExp, binExp, trinExp} a,b,c: Value _ NIL --Only used if type IN {unExp, binExp, trinExp} ]; ValueType: TYPE ~ {unassigned, symbolRef, integer, unExp, binExp, trinExp}; Symbol: TYPE ~ REF SymbolRec; SymbolRec: TYPE ~ RECORD [ name: Rope.ROPE, --The text in the robot file value: Value --What it equals ]; MaxSymbolIndex: PRIVATE INT ~ 1499; --Should be `fairly' prime Index: TYPE ~ [0..MaxSymbolIndex); --An index into a symbol table SymbolTable: TYPE ~ REF SymbolTableRec; SymbolTableRec: TYPE ~ ARRAY Index OF Symbol; opIfThenElse: TrinOp; opOR, opAND, opMOD, opLT, opEQ, opGT, opNE, opGE, opLE, opPlus, opMinus, opTimes, opDivide: BinOp; opNOT, opUMinus: UnOp; ApplyUnaryFcn: PROC [fcn: UnOp, a: Value] RETURNS [z: Value]; ApplyBinaryFcn: PROC [fcn: BinOp, a,b: Value] RETURNS [z: Value]; ApplyTrinaryFcn: PROC [fcn: TrinOp, a,b,c: Value] RETURNS [z: Value]; Eval: PROC [value: Value, s: SymbolTable _ NIL] RETURNS [z: Value]; NewUnassignedValue: PROC RETURNS [z: Value]; NewValueFromInteger: PROC [a: INTEGER] RETURNS [z: Value]; NewSymbolTable: PROC RETURNS [s: SymbolTable]; RopeToSymbolIndex: PROC [r: Rope.ROPE, s: SymbolTable] RETURNS [index: Index]; NextIndex: PROC [in: Index] RETURNS [out: Index] ~ INLINE {RETURN[IF in=0 THEN MaxSymbolIndex-1 ELSE in-1]}; ValueOfSymbol: PROC [index: Index, s: SymbolTable _ NIL] RETURNS [v: Value] ~ INLINE { RETURN [ Eval[NEW[ValueRec _ [type: symbolRef, value: index]], s] ]; }; AssignValueToSymbol: PROC [v: Value, index: Index, s: SymbolTable] ~ INLINE { IF s[index]=NIL THEN ERROR ELSE s[index].value _ v; }; ResolveSymbolTable: PROC [s: SymbolTable] RETURNS [unresolved: BOOLEAN]; }. ¨RobotEvaluator.mesa Created Monday, May 21, 1984 10:38 pm PDT Last edited by Eric Nickell, October 27, 1984 11:55:55 am PDT Apply the specified function to the given values. fcn should be a TrinOp, BinOp, or UnOp. ApplyFcn will try to resolve the value if possible by calling Eval before it returns. Apply the specified function to the given values. fcn should be a TrinOp, BinOp, or UnOp. ApplyFcn will try to resolve the value if possible by calling Eval before it returns. Apply the specified function to the given values. fcn should be a TrinOp, BinOp, or UnOp. ApplyFcn will try to resolve the value if possible by calling Eval before it returns. Evaluate the value. Specifically, if the value was originally defined as a function of other values that were then unassigned, but are at the time of the call to Eval, then Eval will return a Value that is an INTEGER rather than a complex type. Returns a new Value which is marked as being `unassigned'. Returns a new Value which has the given INTEGER value. Looks for the name in the symbol table already. If it fails to find it, it will add it. For those procedures that need to enumerate the indices of a symbol table Ê`˜Jšœ™Jšœ)™)J™=J™šÏk ˜ Jšœœœ˜J˜—šœœ œ˜%J˜—Jšœœœ ˜Jšœœœ ˜Jšœœœ ˜JšÏnœœœœœœœ˜>Jšžœœœœœœœ˜AJšž œœœœ œœœ˜DJ˜Jšœœœ ˜šœ œœœ˜ J˜Jšœ œÏc.˜EJšœœœœŸ/˜FJšœœŸ-˜FJ˜—Jšœ œ<˜KJ˜Jšœœœ ˜šœ œœ˜Jšœ œŸ˜/JšœŸ˜!J˜—Jšœœœ Ÿ˜?JšœœŸ˜BJšœ œœ˜'šœœœœ˜-J˜—J˜J˜J˜bJ˜J˜šž œœœ ˜=J™±J˜—šžœœœ ˜AJ™±J˜—šžœœœ ˜EJ™±J˜—šžœœ!œœ ˜CJšœ„Ïbœn™õJ™—šžœœœ ˜,J™:J™—šžœœœœ ˜:J™6J˜—šžœœœ˜.J˜—šžœœ œœ˜NJ™XJ™—šž œœ œ˜9J™IJš œœœœœ˜2J˜—š ž œœ!œœœ˜VJšœœ3˜DJšœ˜J˜—šžœœ,œ˜MJš œ œœœœ˜3J˜—Jšžœœœœ˜HJ˜—…—®¶