PROGRAM DICTIONARY OR LEXICOGRAPHIC TREE Challenge : run this program in ORCA/Pascal then migrate it in ORCA/C then port it to GNO. The trees are the key elements of programming a compiler. program Dictionary_Example; { This is a simple dictionary program. Words can be inserted into the } { dictionary. The dictionary is displayed after each word is inserted. } type Pointer = ^Node; Node = record Value : string; Left_link : Pointer; Right_link : Pointer end; Header_node = record Title : string; Link : Pointer end; Tree = ^Header_node; var Dictionary : Tree; Word : string; Response : char; {*********************************************************************} procedure Create_Dictionary_Header(var Header : Tree); begin new(Header); Header^.Title := 'Sample Dictionary'; Header^.Link := nil; end; {*********************************************************************} procedure Insert_Word(var P:Pointer; Word:string); begin {Test if pointer P is nil.} if P=nil then {add word to the dictionary} begin new(P); with P^ do begin Value := Word; Left_link := nil; Right_link := nil end end else if Word < P^.Value then {Test if the word is to be inserted to the left of node P.} Insert_Word(P^.Left_link, Word) else if Word > P^.Value then {Test if the word is to be inserted to the right of node P.} Insert_Word(P^.Right_link, Word); else {The word already exists in the dictionary.} begin write('The word ', Word ,' presently exist'); writeln('in dictionary.'); end; end; {Insert_Word} {*********************************************************************} procedure Print_Word(P:Pointer); begin {Test if node P is not nil.} if P <> nil then {traverse the binary tree in inorder} begin Print_Word(P^.Left_link); write(P^.Value, ' '); Print_Word(P^.Right_link); end else {reached a link that is nil} ; end; {Print_Word} {*********************************************************************} procedure Display_Dictionary(Header:Tree); var P:Pointer; begin P:=Header^.Link; if P <> nil then Print_Word(P) else writeln('Dictionary is empty.'); writeln; end; {*********************************************************************} begin {Body of the main program} {Show Text window for displaying prompts.} ShowText; {Create header for dictionary.} Create_Dictionary_Header(Dictionary); {Display contents of the dictionary.} Display_Dictionary(Dictionary); repeat {Prompt for next word.} write('Enter next word : '); readln(Word); {Insert new word in dictionary.} Insert_Word(Dictionary^.Link, Word); writeln; {Display contents of dictionary.} Display_Dictionary(Dictionary); writeln; {Prompt user to continue.} write('Enter Y to continue inserting words, N to quit : '); readln(Response); until Response <> 'Y'; Display_Dictionary(Dictionary); end.