File: ExprRead.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Created by: Mayo, July 23, 1984 3:50:47 pm PDT
Last Edited by: Mayo, August 15, 1984 12:40:10 pm PDT
-- ExprRead: Read 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.
-- This module uses the slot named '&' in the passed symbol tables as a temporary placeholder. Anything that the caller places there might be destroyed.
DIRECTORY
AMTypes USING [TV],
IO USING [STREAM],
SymTab USING [Ref],
Rope USING [ROPE];
ExprRead: CEDAR DEFINITIONS = BEGIN
Error: ERROR [ec: ErrorCode, msg: Rope.ROPE];
ErrorCode: TYPE = {Null,     -- never raised
CouldNotEval,       -- could not evaluate expression
NoValue,         -- expression didn't return a value
Syntax,         -- bad expression syntax
FileError,         -- could not read from file
Missing,         -- raised by the FetchXXX procs.
BadType,        -- raised by the FetchXXX procs.
NotTVTable        -- the passed SymTab had something other than a TV!
};
Evaluate one expression and return a TV for it's result.
Eval: PROC [expr: Rope.ROPE, symTab: SymTab.Ref] RETURNS [AMTypes.TV];
Evaluate one assignment statement of the form 'var ← expr', and update var in the symbol table.
Assign: PROC [line: Rope.ROPE, symTab: SymTab.Ref];
Read a file that contains one assignment statement per line, returning a symbol table
ReadStream: PROC [stream: IO.STREAM] RETURNS [symTab: SymTab.Ref];
ReadFile: PROC [fileName: Rope.ROPE] RETURNS [symTab: SymTab.Ref];
Combine 2 tables of TVs to yield a third. Values in the second table override values in the first table if there is a conflict.
CombineTabs: PROC [first, second: SymTab.Ref] RETURNS [SymTab.Ref];
Handy procs for looking up & storing parameters in a SymTab of TVs.
These procs may raise Error[NotTVTable] and Error[FetchError].
IF we can't find the parameter AND missingOK is false THEN we raise Error[Missing] with a message like:
"Parameter XYZ is missing."
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."
-- 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)
FetchBool: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: BOOL];
FetchInt: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: INT];
FetchCardinal: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: CARDINAL];
FetchAtom: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: ATOM];
FetchRope: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: Rope.ROPE];
-- General hook for other types.
FetchRefAny: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: REF ANY];
-- lists (add more if you wish!)
FetchListOfBool: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: LIST OF BOOL];
FetchListOfInt: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: LIST OF INT];
FetchListOfCardinal: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: LIST OF CARDINAL];
FetchListOfAtom: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: LIST OF ATOM];
FetchListOfRope: PROC [params: SymTab.Ref, name: Rope.ROPE, missingOK: BOOLFALSE] RETURNS [found: BOOL, val: LIST OF Rope.ROPE];
-- Base types & ref any. For other types, create a pointer to it and do StoreRefAny. Same for lists.
StoreBool: PROC [params: SymTab.Ref, name: Rope.ROPE, val: BOOL];
StoreInt: PROC [params: SymTab.Ref, name: Rope.ROPE, val: INT];
StoreCardinal: PROC [params: SymTab.Ref, name: Rope.ROPE, val: CARDINAL];
StoreAtom: PROC [params: SymTab.Ref, name: Rope.ROPE, val: ATOM];
StoreRope: PROC [params: SymTab.Ref, name: Rope.ROPE, val: Rope.ROPE];
StoreRefAny: PROC [params: SymTab.Ref, name: Rope.ROPE, val: REF ANY];
END.