CDExpr.mesa
Copyright © 1984 by Xerox Corporation. All rights reversed.
Created by: Mayo, July 23, 1984 3:50:47 pm PDT
Last Edited by: Serlet, January 4, 1985 7:03:15 pm PST
CDExpr:
CEDAR
DEFINITIONS =
BEGIN
Utilities
ROPE: TYPE = Rope.ROPE;
Error: ERROR [ec: ErrorCode, msg: ROPE];
ErrorCode:
TYPE = {
CouldNotEval, -- could not evaluate expression
NoValue, -- expression didn't return a value
Syntax, -- bad expression syntax
FileError, -- could not read from file
BadType, -- raised by the FetchXXX procs.
NotTVTable -- the passed SymTab had something other than a TV!
};
Reading and storing parameters
Evaluates one assignment statement of the form 'var ← expr', and updates var in the symbol table. Returns TRUE if new value, FALSE if previous value overwritten.
Assign: PROC [symTab: SymTab.Ref, line: ROPE] RETURNS [BOOL];
Reads a stream or a file (for convenience) that contains one assignment statement per line, returning a symbol table.
ReadStream: PROC [stream: IO.STREAM] RETURNS [symTab: SymTab.Ref];
ReadFile: PROC [fileName: ROPE] RETURNS [symTab: SymTab.Ref];
Storing parameters
Base types (add more if you wish!). For other types, create a pointer to it and do StoreRef. Same for lists. The boolean returned value has the same meaning as in SymTab.Store, i.e. is TRUE if new value, FALSE if previous value overwritten.
StoreBool: PROC [symTab: SymTab.Ref, name: ROPE, val: BOOL] RETURNS [BOOL];
StoreInt: PROC [symTab: SymTab.Ref, name: ROPE, val: INT] RETURNS [BOOL];
StoreAtom: PROC [symTab: SymTab.Ref, name: ROPE, val: ATOM] RETURNS [BOOL];
StoreRope: PROC [symTab: SymTab.Ref, name: ROPE, val: ROPE] RETURNS [BOOL];
General hook for other types.
StoreRef: PROC [symTab: SymTab.Ref, name: ROPE, val: REF] RETURNS [BOOL];
Fetching parameters
Base types (add more if you wish!). Non-ref values are stored as refs to the value. (That is, INT is stored as REF INT).
These procs may raise Error[NotTVTable] if the table contains non-TV values.
If the parameter is not of the expected type then we raise Error[BadType] with a message like:
"Parameter XYZ is of the wrong type, it should be a rope."
FetchBool: PROC [symTab: SymTab.Ref, name: ROPE] RETURNS [found: BOOL, val: BOOL];
FetchInt: PROC [symTab: SymTab.Ref, name: ROPE] RETURNS [found: BOOL, val: INT];
FetchAtom: PROC [symTab: SymTab.Ref, name: ROPE] RETURNS [found: BOOL, val: ATOM];
FetchRope: PROC [symTab: SymTab.Ref, name: ROPE] RETURNS [found: BOOL, val: ROPE];
General hook for other types.
FetchRef: PROC [symTab: SymTab.Ref, name: ROPE] RETURNS [found: BOOL, val: REF];
Operations on SymTab of TV
Combines 2 tables of TVs to yield a third. Values in the winner table override values in the loser table if there is a conflict. With only first argument, this proc copies the table. Arguments are not changed.
CombineTabs: PROC [winner: SymTab.Ref, loser: SymTab.Ref ← NIL] RETURNS [SymTab.Ref];
Enumerates pairs currently in symbol table in unspecified order. Pairs inserted/deleted during enumeration may or may not be seen. Applies action to each pair until action returns TRUE or no more pairs. Returns TRUE if some action returns TRUE
Pairs: PROC [symTab: SymTab.Ref, action: SymTab.EachPairAction] RETURNS [BOOL];
END.