! Dictionary package !Dictionaries are organised as binary trees with parent pointers. !Balancing is for further study. Dictionary descriptors contain !a pointer to the root of the tree, plus a pointer to an alternative !dictionary, to be searched if the sought entry is not found in the !current dictionary's tree. Dictionary cells are normally allocated !economically, i.e. they do not allow space for a 255 character string !at the end, but only enough. %recordformatspec dict cell fm %recordformat dict fm - (%record(dict fm)%name alt,%record(dict cell fm)%name tree) %recordformat dict cell fm - (%record(dict cell fm)%name parent,left,right, %integer token,%string(255)s) %integerfn make entry(%string(255)s,%record(dict fm)%name d) ! Make an entry for name S in dictionary D and return the ! address of the token field for that entry. %record(dict cell fm)%name c,n,p==nil toupper(s) n == record(heapget(sizeof(n)-255+length(s))) n_parent == nil; n_left == nil; n_right == nil; n_token = 0; n_s = s %if d_tree==nil %start d_tree == n; %result = addr(n_token) %finish c == d_tree %cycle %signal 5,,,"Dictionary corrupt" %unless c_parent==p p == c %if s<=c_s %start %if s=c_s %start dispose(n); %result = addr(c_token) %finish %if c_left==nil %start c_left == n; n_parent == c; %result = addr(n_token) %finish c == c_left %elseif c_right==nil c_right == n; n_parent == c; %result = addr(n_token) %finishelse c == c_right %repeat %end %integerfn find entry(%string(255)s,%record(dict fm)%name d) ! Find the entry for name S in dictionary D, returning the ! address of its token field (or 0 if not found). ! Looks down ALT tree %record(dict cell fm)%name c toupper(s) %cycle %result = 0 %if d==nil c == d_tree %cycle %exit %if c==nil %result = addr(c_token) %if s=c_s %if s