DIRECTORY IO USING [STREAM], Rope USING [ROPE], SymTab USING [EachPairAction, Ref]; CDExpr: CEDAR DEFINITIONS = BEGIN 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! }; Assign: PROC [symTab: SymTab.Ref, line: ROPE] RETURNS [BOOL]; ReadStream: PROC [stream: IO.STREAM] RETURNS [symTab: SymTab.Ref]; ReadFile: PROC [fileName: ROPE, wDir: ROPE _ NIL] RETURNS [symTab: SymTab.Ref]; 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]; StoreRef: PROC [symTab: SymTab.Ref, name: ROPE, val: REF] RETURNS [BOOL]; 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]; FetchRef: PROC [symTab: SymTab.Ref, name: ROPE] RETURNS [found: BOOL, val: REF]; CombineTabs: PROC [winner: SymTab.Ref, loser: SymTab.Ref _ NIL] RETURNS [SymTab.Ref]; Pairs: PROC [symTab: SymTab.Ref, action: SymTab.EachPairAction] RETURNS [BOOL]; END. 6CDExpr.mesa Copyright c 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 Bertrand Serlet May 28, 1986 11:58:08 am PDT This module allows reading expressions of the form 'var _ expr' or 'var ~ expr'. If the operator is '_ then the expr is evaluated using symbols in a symbol table, or things in the global naming context. See Interpreter.mesa for more details. If the operator is '~ then expr is simply treated as a rope which is then assigned to var. A way of using this interface is to create a text file assigning values to parameters, and in the client program to read this file (with ReadFile) and then fetch the necessary parameters (with the appropriate Fetch proc). Another way is just to Create a SymTab and then do Stores and Fetches. The difference with ordinary SymTabs is that the values are TV, so to be compatible with the interpreter. That means that Procs from the SymTab interface that do not deal with values are still directly applicable, for example: Create, Delete, and GetSize. This module uses the slot named '&' in the passed symbol tables as a temporary placeholder. Anything that the caller places there might be destroyed. Utilities 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. Reads a stream that contains one assignment statement per line, returning a symbol table. For conveniency only. Reads a stream or a file that contains one assignment statement per line, returning a symbol table. 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. General hook for other types. 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." General hook for other types. 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. 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 สa˜šœ ™ Jšœ ฯmœ1™œ™ข—J˜š ž œŸœ ŸœŸœŸœ˜BJ™Y—J˜š žœŸœ ŸœŸœŸœŸœ˜OJ™z——™Jšœ กœ2 œ_ก7™๒Jš ž œŸœŸœŸœŸœŸœ˜KJš žœŸœŸœŸœŸœŸœ˜IJš ž œŸœŸœŸœŸœŸœ˜KJš ž œŸœŸœŸœŸœŸœ˜KJ˜š žœŸœŸœŸœŸœŸœ˜IJ™——™Jšกzœ็™แJš ž œŸœŸœŸœ ŸœŸœ˜RJš žœŸœŸœŸœ ŸœŸœ˜PJš ž œŸœŸœŸœ ŸœŸœ˜RJš ž œŸœŸœŸœ ŸœŸœ˜RJ˜š žœŸœŸœŸœ ŸœŸœ˜PJ™——™šž œŸœ*ŸœŸœ˜UJ™า—J˜šžœŸœ5ŸœŸœ˜OJšœ๕™๕—J˜JšŸœ˜—J˜J˜J˜—…—ค;