ExpressTree.mesa
Handles the Expression parsing trees for the Express Package
Created Tuesday, July 17, 1984 3:05 pm PDT
Last edited by Eric Nickell, July 18, 1984 2:04:50 am PDT
DIRECTORY
Interface USING [Item],
;
ExpressTree: CEDAR DEFINITIONS ~ {
XType: TYPE ~ {id, constant, unX, binX, trinX, fcn};
XTree: TYPE ~ REF XTreeRec;
XTreeRec: TYPE ~ RECORD [
SELECT type: XType FROM
id => [op: ATOM],
constant => [value: REAL],
unX => [op: ATOM, exp1: XTree],
binX => [op: ATOM, exp1, exp2: XTree],
trinX => [op: ATOM, exp1, exp2, exp3: XTree],
fcn => [proc: PROC ANY RETURNS ANY, args: LIST OF XTree]
ENDCASE
];
IdX: TYPE ~ id XTreeRec;
ConstantX: TYPE ~ constant XTreeRec;
UnX: TYPE ~ unX XTreeRec;
BinX: TYPE ~ binX XTreeRec;
TrinX: TYPE ~ trinX XTreeRec;
FcnX: TYPE ~ fcn XTreeRec;
XTreeFromId: PROC [op: ATOM] RETURNS [x: XTree];
XTreeFromConstant: PROC [value: REAL] RETURNS [x: XTree];
ApplyUnOp: PROC [op: ATOM, exp1: XTree] RETURNS [x: XTree];
ApplyBinOp: PROC [op: ATOM, exp1, exp2: XTree] RETURNS [x: XTree];
ApplyTrinOp: PROC [op: ATOM, exp1, exp2, exp3: XTree] RETURNS [x: XTree];
ApplyFcn: PROC [proc: PROC ANY RETURNS ANY, args: LIST OF XTree] RETURNS [x: XTree];
EnumerateProc: TYPE ~ PROC [x: XTree] RETURNS [continue: BOOLEANTRUE, client: REF ANYNIL];
EnumChildren: PROC [x: XTree, enum: EnumerateProc] RETURNS [finished: BOOLEAN, client: REF ANY];
Enumerates only the immediate children of x. Finished is TRUE iff all EnumerateProcs called returned TRUE, i.e., none of them discontinued the iteration. Note that client is NIL if enum never had continue go FALSE. If continue did go FALSE, then client is passed back from the EnumerateProc.
EnumDescendants: PROC [x: XTree, beforeChildren, afterChildren: EnumerateProc ← NIL] RETURNS [finished: BOOLEAN, client: REF ANY];
Enumerates all the descendants of x. beforeChildren and afterChildren are both called for each node of the tree (including terminals), beforeChildren before the children of that node, and afterChildren after the children of that node (nifty how that works, huh?). Finished is TRUE iff all EnumerateProcs called returned TRUE, i.e., none of them discontinued the iteration. Note that client is NIL if enum never had continue go FALSE. If continue did go FALSE, then client is passed back from the EnumerateProc.
}.