home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / text / folddemo.text (.txt) < prev    next >
Oberon Text  |  1977-12-31  |  4KB  |  115 lines

  1. Syntax10.Scn.Fnt
  2. FoldElems
  3. Syntax10.Scn.Fnt
  4. This is a short demo that shows the use of fold elements.
  5. a) Middle-click at a filled triangle (e.g. behind the procedure Insert). The procedure body is shown.
  6.     Middle-click at the non-filled triangle. The procedure body is collapsed again.
  7. b) Expand procedure Insert and then its local procedure Ins. You find two pseudocode actions that can also be expanded.
  8. c) Make a new fold element by selecting some text and executing FoldElems.Insert
  9. d) Compile this file with
  10.         FoldComp.Compile */s
  11.     A (deliberate) error is reported. Set the caret at the beginning of the text and execute
  12.         FoldComp.ShowError .
  13.     The error location is revealed and marked with a small rectangle. middle-click at it to get the error message.
  14. e) FoldElems.Expand expands all elements. FoldElems.Collapse collapses them all.
  15. Syntax10i.Scn.Fnt
  16. Syntax10.Scn.Fnt
  17.     VAR s: Texts.Scanner;
  18. BEGIN
  19.     Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
  20.     IF s.class = Texts.Name THEN COPY(s.s, n) ELSE n := "" END
  21. END GetName;
  22. Syntax10.Scn.Fnt
  23. FoldElems
  24. Syntax10.Scn.Fnt
  25. FoldElems
  26. Syntax10.Scn.Fnt
  27. FoldElems
  28. Syntax10.Scn.Fnt
  29. GraphicElems
  30. Alloc
  31. Rectangles
  32. Syntax10.Scn.Fnt
  33. father
  34. Syntax10i.Scn.Fnt
  35. p := tree; father := NIL;
  36.         WHILE p # NIL DO
  37.             IF elem.name = p.name THEN RETURN END;
  38.             father := p;
  39.             IF elem.name < p.name THEN p := p.left ELSE p := p.right END
  40.         END;    
  41. see picture
  42. Syntax10i.Scn.Fnt
  43. Syntax10.Scn.Fnt
  44. IF father = NIL THEN tree := elem
  45.         ELSIF elem.name < father.name THEN father.left := elem
  46.         ELSE father.right := elem
  47.         END
  48.         VAR p, father: Node;
  49.     BEGIN elem.left := NIL; elem.right := NIL;
  50. find insertion place (father)
  51. insert elem under father
  52.     END Ins;
  53.     VAR x: Node;
  54.     PROCEDURE Ins(elem: Node);    
  55. BEGIN
  56.     NEW(x); GetName(x.name); Ins(x)
  57. END Insert;
  58. Syntax10.Scn.Fnt
  59. FoldElems
  60. Syntax10.Scn.Fnt
  61.     BEGIN
  62.         IF x # NIL THEN
  63.             P(x.left); Texts.WriteString(w, x.name); Texts.WriteLn(w); P(x.right)
  64.         END
  65.     END P;
  66.     PROCEDURE P(x: Node);    
  67. BEGIN
  68.     P(tree); Texts.Append(Oberon.Log, w.buf)
  69. END Print;
  70. Syntax10.Scn.Fnt
  71. FoldElems
  72. Syntax10.Scn.Fnt
  73.         VAR p, x, y, father: Node;
  74.     BEGIN
  75.         p := tree; father := NIL;
  76.         WHILE (p # NIL) & (name # p.name) DO
  77.             father := p;
  78.             IF name < p.name THEN p := p.left ELSE p := p.right END
  79.         END;
  80.         IF p # NIL THEN
  81.             IF p.right = NIL THEN x := p.left
  82.             ELSIF p.right.left = NIL THEN x := p.right; x.left := p.left
  83.             ELSE
  84.                 x := p.right; WHILE x.left # NIL DO y := x; x := x.left END;
  85.                 y.left := x.right;
  86.                 x.left := p.left; x.right := p.right
  87.             END;
  88.             IF father = NIL THEN tree := x
  89.             ELSIF name < father.name THEN father.left := x 
  90.             ELSE father.right := x 
  91.             END
  92.         END
  93.     END Del;
  94.     VAR name: Name;
  95.     PROCEDURE Del(name: Name);    
  96. BEGIN
  97.     GetName(name); Del(name);
  98. END Delete;
  99. read me
  100. MODULE FoldDemo;
  101. IMPORT Oberon, Texts;
  102.     Name = ARRAY 32 OF CHAR;
  103.     Node = POINTER TO NodeDesc;
  104.     NodeDesc = RECORD
  105.         name: Name;
  106.         left, right: Node
  107.     END;
  108. VAR tree: Node; w: Texts.Writer;
  109. PROCEDURE GetName(VAR n: Name);    
  110. PROCEDURE Insert*;    
  111. PROCEDURE Print*;    
  112. PROCEDURE Delete*;    
  113. BEGIN tree := NIL; Texts.OpenWriter(w)
  114. END FoldDemo.
  115.