ttree.rig 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #DICTIONARY
  2. -- This test shows use of traditional tree and of atomic table utility
  3. -- It creates dictionary of all words in given file
  4. -- and removes all words which appear more than once.
  5. -- Information comes through parameters of task or interactively;
  6. $B:=#PARM(T);
  7. OPEN S ' ';
  8. $MEMORY:=$B[1];
  9. IF NOT $MEMORY ->
  10. LOOP
  11. $MEMORY:=
  12. #CALL_PAS(1 'Enter size of the table {elements, <=total / 5} ');
  13. -- 21=VAL 1=WRITE/READ
  14. IF $MEMORY>0 -> BREAK FI;
  15. END;
  16. FI;
  17. $TAB:=#CALL_PAS(61 $MEMORY); -- create
  18. $TAB2:=#CALL_PAS(61 $MEMORY); -- create
  19. IF ($TAB<=0)OR($TAB2<=0)
  20. -> #CALL_PAS( 1 'STOP ! ERROR IN CREATION ');FI;
  21. $FILE:=$B[2];
  22. IF NOT $FILE ->
  23. $FILE:=#CALL_PAS(1 'Enter file name ');
  24. FI;
  25. $LIST:=#CALL_PAS(3 $FILE); -- Pascal scanner
  26. S<<' Tree creation ';
  27. FORALL $E IN $LIST DO
  28. IF #IDENT($E) ->
  29. IF $DICT.$E -> $DICT.$E+:=1
  30. ELSIF T -> $DICT++:=<.$E:1.>
  31. FI;
  32. FI;
  33. OD;
  34. S<<' Tree copy ';
  35. $DICT1:=COPY($DICT);
  36. S<<' Tree update ';
  37. FORALL $E IN $DICT DO
  38. IF $DICT.$E>1 -> $DICT1.$E:=NULL FI;OD;
  39. S<<' Table creation ';
  40. FORALL $E IN $LIST DO
  41. IF #IDENT($E) ->
  42. $V:=#CALL_PAS(63 $TAB $E); -- get n
  43. IF $V->#CALL_PAS(62 $TAB $E $V+1) -- put n+1
  44. ELSIF T-> #CALL_PAS(62 $TAB $E 1) -- put 1
  45. FI;
  46. FI;
  47. OD;
  48. S<<' Table copy ';
  49. $TABCOPY:=#CALL_PAS(65 $TAB); -- unpack
  50. #CALL_PAS(66 $TAB2 $TABCOPY); -- pack
  51. S<<' Table update ';
  52. $I:=1;
  53. $ENDLOOP:=#CALL_PAS(64 $TAB); -- card
  54. LOOP
  55. $SEL:=#CALL_PAS(67 $TAB $I); -- num to sel
  56. $VAL:=#CALL_PAS(63 $TAB $SEL); -- get
  57. IF $VAL>1 -> #CALL_PAS(62 $TAB2 $SEL NULL); -- put null
  58. FI;
  59. IF $I=$ENDLOOP -> BREAK; FI;
  60. $I+:=1;
  61. END;
  62. S<<' End of work ; test for correctness:';
  63. IF $DICT=#CALL_PAS(65 $TAB) -> -- card
  64. S<< SOURCES ARE EQUAL
  65. ELSIF T->
  66. S<< SOURCES ARE DIFFERENT;
  67. FI;
  68. IF $DICT1=#CALL_PAS(65 $TAB2) -> -- card
  69. S<< RESULTS ARE EQUAL
  70. ELSIF T->
  71. S<< RESULTS ARE DIFFERENT;
  72. FI;
  73. S<< 'TOTAL WORDS=' #CALL_PAS(64 $TAB)
  74. ' ONCE OCCURED=' #CALL_PAS(64 $TAB2) ;
  75. ##