Linked list of binary trees plus what ?
The EditKeys utility which effectively allows defining 'hot-keys' [macro definitions of user chosen strings are activated by the <insert> key] seems worth investigating. In order to understand certain parts of the manual/Tool Eg.: "Text stretches are pushed on a parameter stack when processed. Built-in functions may pop parameter(s) from that stack. ^0 pops a parameter and causes textual insertion. ^1 pops a parameter and inserts the corresponding ascii character. ..etc.", I looked at the source code. But the data-structures confuse me. Here are some:-- SequenceDesc = RECORD next: Sequence; <-- linked list sym: INTEGER; cmd: CHAR; def: Definition; stretch: Texts.Buffer END; DefinitionDesc = RECORD left, right: Definition; <-- binary tree in: BOOLEAN; trig: Ident; <-- ARRAY IdentLen OF CHAR seq: Sequence END; It seems to me that 'Sequence' is a linked list of Definitions with nodes: sym, cmd, stretch. And that Definition is a binary tree. But the confusing/un-natural thing is that Definition's nodes have also further Sequence-linkedLists ! Q - is this correct ? I'm guessing that the data structures employed are those which naturally occur for macro/compilers/?? Can anybody give me a clue of how to better understand this application ? It originates from 1992 and the full use of it's features may be very usefull. == Chris Glur.
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
participants (2)
-
B. Smith-Mannschott -
Chris Glur