[Oberon] Linked list of binary trees plus what ?
B. Smith-Mannschott
benpsm at gmail.com
Sat Dec 8 21:08:02 MET 2007
I struggled through the code for a little while today and have a few
observations:
defs:Definition is the root of a binary search tree keyed by trig
(short string identifying a "trigger")
The Definition referenced directly by defs, however, is a "dummy"
node, in that it has the trigger "" (empty string), which is
lexographically less than any valid trigger. This is why this root
node never has a left child.
See PROCEDURE Trigger, where we set d to defs.right before entering
the while loop to search the tree.
So, defs is the root of a binary search tree, where Definitions can be
looked up by name.
Let's take a look at PROCEDURE Expand
A Definition consists of a Sequence of 'actions', most of which are
'commands'. For example, the command execCmd pops the name a command
from the stack. This name is looked up in defs and then called by
recursing on Expand.
ELSIF seq.cmd = execCmd THEN PopArg(def, Texts.Name, S, stack);
IF errs = 0 THEN COPY(S.s, name); d := Find(name, trig, FALSE);
IF d # NIL THEN Expand(d, stack, args, params)
ELSE Err(def, "exec of undefined macro")
END
END
Now, it turns out that there's a second way to call an existing
definition, only in this case it is resolved at compile time,
presumably when the name of an existing definition is encountered by
the macro parser (though I haven't found that bit yet).
In any case, when the element in a definitions sequence has sym =
nameSym then it's def is a definition to be executed. (Which
presumably also occurs in the search tree somewhere else, though this
isn't relevant to this view of the definiton).
ELSIF seq.sym = nameSym THEN Expand(seq.def, stack, args, params)
Well, that's as far as I got before I moved on to another task. The
code is very WCS, which makes it hard to understand without
considerable contemplation.
// ben
More information about the Oberon
mailing list