-- basic Interscript items
Id: TYPE ~ Rope.ROPE;
Universal: TYPE ~ ATOM;
LinkSet: TYPE ~ RECORD[sources: SpanList, targets: SpanList];
SpanList: TYPE ~ LIST OF Span;
Span: TYPE ~ REF SpanRec;
SpanRec: TYPE;
Value: TYPE ~ REF ValueRec;
ValueRec:
TYPE ~
RECORD[
SELECT t: *
FROM
nil => [],
number => [
SELECT numTag: *
FROM
int => [int: INT],
real => [real: REAL]
ENDCASE],
string => [r: Rope.ROPE],
span => [--TBD--],
expr => [expr: ExprTree]
ENDCASE];
ExprTree: TYPE ~ REF ExprTreeRec;
ExprTreeRec:
TYPE ~
RECORD[
vp:
SELECT type: *
FROM
monadic => [op: Operator, left: ExprTree],
dyadic => [op: Operator, left, right: ExprTree],
terminal => [v: Value]
ENDCASE];
-- lexical definitions
Token: TYPE ~ REF TokenRec;
TokenRec:
TYPE ~
RECORD[
first, last: STREAMPosition, -- to record where a token came from
vp:
SELECT type: OfToken
FROM
id => [id: Id],
univ => [univ: Universal], -- includes keywords also
int => [int: INT],
real => [real: REAL],
string => [s: Rope.ROPE],
op => [op: Operator],
sep => [s: Separator],
bracket => [b: Bracket],
literal => [lit: Literal]
ENDCASE
];
OfToken: TYPE ~ {id, univ, int, real, string, op, sep, bracket, literal};
Operator: TYPE ~ {plus, minus, times, slash};
Separator: TYPE ~ {semicolon, dot, percent, exclamation, verticalBar, localGets, globalGets, upArrow, colon};
Bracket: TYPE ~ {lParen, rParen, lBracket, rBracket, lBrace, rBrace, quote};
Literal: TYPE ~ {nil, true, false};
STREAMPosition: TYPE ~ INT;
InitScan: PROCEDURE [stream: IO.STREAM, bindTbl: BTHandle, z: ZONE];
GetToken: PROCEDURE RETURNS [t: Token];
-- bindings
BTHandle: TYPE ~ REF BindingTable;
BindingTable: TYPE;
Binding: TYPE ~ REF BindingRec;
BindingRec: TYPE ~ RECORD[id: Id, m: BindingMode, v: Value];
BindingMode: TYPE ~ {local, global} ← local;
InitBindingTable: PROCEDURE [z: ZONE] RETURNS [bt: BTHandle];
AddBinding:
PROCEDURE [self: BTHandle, b: Binding];
adds the binding to the table in the current scope. Any extant binding for the same id in the current scope is overwritten.
GetBinding:
PROCEDURE [self: BTHandle, id: Id]
RETURNS [binding: Binding];
Returns id's binding, or NIL if unbound
GetBindings:
PROCEDURE [self: BTHandle, ids:
LIST
OF Id]
RETURNS [bindings:
LIST
OF Binding];
for each id in the list, returns its binding, or NIL if unbound
Scope: TYPE ~ RECORD[uid: INT];
NewScope:
PROCEDURE [self: BTHandle]
RETURNS [s: Scope];
pushes a new scope and returns a handle for it
PopScope:
PROCEDURE [self: BTHandle, s: Scope];
Pops the current scope, which s must identify (else error ScopeError[inputError] is generated).