FormulaOperatorsImpl.mesa
Last Edited by: Arnon, July 19, 1985 2:54:46 pm PDT
DIRECTORY
Rope,
IO,
Basics,
Atom,
Convert,
AlgebraClasses,
MathConstructors,
FormulaOperators;
FormulaOperatorsImpl: CEDAR PROGRAM
IMPORTS IO, Rope, AlgebraClasses, MathConstructors
EXPORTS FormulaOperators
= BEGIN OPEN FormulaOperators, Convert, AC: AlgebraClasses;
Types
FormulaOperatorsError: PUBLIC SIGNAL [reason: ATOM ← $Unspecified] = CODE;
bitsPerWord: CARDINAL = Basics.bitsPerWord;
CARD: TYPE = LONG CARDINAL;
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
TypeError: PUBLIC ERROR [message: ATOM ← $Unspecified] = CODE;
Variables
ClassPrintName: AC.PrintNameProc = {
RETURN["FormulaOperators"];
};
ClassLegalFirstChar: AC.LegalFirstCharOp = {
SELECT char FROM
'a, 'o, 'n, 'l, 'g, 'e, 'd => RETURN[TRUE];
'A, 'O, 'N, 'L, 'G, 'E, 'D => RETURN[TRUE];
ENDCASE;
RETURN[FALSE];
};
ClassToExpr: AC.ToExprOp = {
RETURN[MathConstructors.MakeVariable[ToRope[in] ] ];
};
ClassEqual: AC.EqualityOp = {
a: OperatorData ← NARROW[firstArg.data];
b: OperatorData ← NARROW[secondArg.data];
RETURN[a^ = b^];
};
OperatorClass: AC.StructureClass ← NEW[AC.StructureClassRec ← [
category: set,
flavor: "FormulaOperators",
printName: ClassPrintName,
structureEqual: AC.defaultStructureEqualityTest,
isElementOf: AC.defaultElementOfProc,
legalFirstChar: ClassLegalFirstChar,
read: Read,
fromRope: FromRope,
toRope: ToRope,
write: Write,
toExpr: ClassToExpr,
equal: ClassEqual,
propList: NIL
] ];
Operators: PUBLIC AC.Structure ← NEW[AC.StructureRec ← [
class: OperatorClass,
instanceData: NIL
] ];
I/O and Conversion
Read: PUBLIC AC.ReadOp ~ {
rope: Rope.ROPE;
op: Op;
[]← in.SkipWhitespace[];
rope ← in.GetID[];
SELECT TRUE FROM
Rope.Equal[rope, "and"] => op ← and;
Rope.Equal[rope, "AND"] => op ← and;
Rope.Equal[rope, "or"] => op ← or;
Rope.Equal[rope, "OR"] => op ← or;
Rope.Equal[rope, "not"] => op ← not;
Rope.Equal[rope, "NOT"] => op ← not;
Rope.Equal[rope, "lt"] => op ← lt;
Rope.Equal[rope, "LT"] => op ← lt;
Rope.Equal[rope, "le"] => op ← le;
Rope.Equal[rope, "LE"] => op ← le;
Rope.Equal[rope, "gt"] => op ← gt;
Rope.Equal[rope, "GT"] => op ← gt;
Rope.Equal[rope, "ge"] => op ← ge;
Rope.Equal[rope, "GE"] => op ← ge;
Rope.Equal[rope, "eq"] => op ← eq;
Rope.Equal[rope, "EQ"] => op ← eq;
Rope.Equal[rope, "ne"] => op ← ne;
Rope.Equal[rope, "NE"] => op ← ne;
Rope.Equal[rope, "dc"] => op ← dc;
Rope.Equal[rope, "DC"] => op ← dc;
ENDCASE;
RETURN[NEW[AC.ObjectRec ← [
structure: Operators,
data: NEW[Op ← op]
] ] ];
};
FromRope: PUBLIC AC.FromRopeOp = {
stream: IO.STREAMIO.RIS[in];
RETURN[ Read[stream, structure] ];
};
ToRope: PUBLIC AC.ToRopeOp = {
data: OperatorData ← NARROW[in.data];
op: Op ← data^;
SELECT op FROM
= and => RETURN["and"];
= or => RETURN["or"];
= not => RETURN["not"];
= lt => RETURN["lt"];
= le => RETURN["le"];
= gt => RETURN["gt"];
= ge => RETURN["ge"];
= eq => RETURN["eq"];
= ne => RETURN["ne"];
= dc => RETURN["dc"];
ENDCASE;
};
Write: PUBLIC AC.WriteOp = {
IO.PutRope[ stream, ToRope[in] ]
};
END.