home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e051 / 2.ddi / EXAMPLES / TREES.OPS < prev   
Encoding:
Text File  |  1987-07-06  |  2.6 KB  |  126 lines

  1. (literalize node
  2.     name
  3.     level
  4.     lc
  5.     rc
  6.     val)
  7.  
  8. (literalize current
  9.     name)
  10.  
  11. (literalize right_child
  12.     name)
  13.  
  14. (literalize left_child
  15.     name)
  16.  
  17. (literalize pattern
  18.     val)
  19.  
  20. (literalize strategy
  21.     type)
  22.  
  23. (p init
  24.    (start)
  25.   -->
  26.    (write (crlf) Type in an exact match pattern to search for (crlf))
  27.    (bind <val> (accept))
  28.    (write (crlf) Type in breadth or depth to indicate search strategy
  29.           (crlf))
  30.    (bind <strat> (accept))
  31.    (make pattern ^val <val>)
  32.    (remove 1)
  33.    (make get-root)
  34.    (make make-strategy <strat>))
  35.  
  36. (p breath-first-search
  37.    (make-strategy breadth)
  38.    {<strat> (strategy)}
  39.   -->
  40.    (remove 1)
  41.    (modify <strat> ^type breadth)
  42.    (rule-priority do-level high))
  43.  
  44. (p depth-first-search
  45.    (make-strategy depth)
  46.    {<strat> (strategy)}
  47.   -->
  48.    (remove 1)
  49.    (modify <strat> ^type depth)
  50.    (rule-priority do-level low))
  51.  
  52. (p get-root
  53.    (get-root)
  54.    (node ^level 1 ^name <name>)
  55.   -->
  56.    (remove 1)
  57.    (make current ^name <name>))
  58.  
  59. (p dump-nil
  60.    (<< left_child right_child >> ^name nil)
  61.   -->
  62.    (remove 1))
  63.  
  64. (p check-current-found
  65.    (current ^name <name>)
  66.    (pattern ^val <value>)
  67.    (node ^name <name> ^val <value>)
  68.   -->
  69.    (write (crlf) found current value: <value> at <name>)
  70.    (halt))
  71.  
  72. (p check-current-not-found
  73.    (current ^name <name>)
  74.    (pattern ^val <value>)
  75.    (node ^name <name> ^val <> <value> ^lc <lc> ^rc <rc>)
  76.   -->
  77.    (remove 1)
  78.    (make right_child ^name <rc>)
  79.    (make left_child ^name <lc>))
  80.  
  81. (p do-level
  82.    (current ^name <name>)
  83.    (pattern ^val <value>)
  84.    (node ^name <name> ^level <lev> ^val <> <value>
  85.          ^lc <lc> ^rc <rc>)
  86.    {<samlev>
  87.        ( {<child> << left_child right_child >>}
  88.          ^name <aname>)}
  89.    (node ^name <aname> ^level <lev>)
  90.    (strategy ^type <strat>)
  91.   -->
  92.    (write (crlf)
  93.       <strat> searching <child> <aname> at level: <lev>)
  94.    (remove 1 <samlev>)
  95.    (make right_child ^name <rc>)
  96.    (make left_child ^name <lc>)
  97.    (make current ^name <aname>))
  98.  
  99. (p depth-next
  100.    {<cur> (left_child ^name {<name> <> nil})}
  101.    (node ^name <name> ^level <lev>)
  102.    (strategy ^type <strat>)
  103.   -->
  104.    (write (crlf)
  105.       <strat> searching left child <name> at level: <lev>)
  106.    (make current ^name <name>)
  107.    (remove <cur>))
  108.  
  109. (p breadth-next
  110.    {<cur> (right_child ^name {<rname> <> nil})}
  111.    (node ^name <rname> ^level <lev>)
  112.    (strategy ^type <strat>)
  113.   -->
  114.    (write (crlf)
  115.       <strat> searching right child <rname> at level: <lev>)
  116.    (make current ^name <rname>)
  117.    (remove <cur>))
  118.  
  119. (priority low -2)
  120.  
  121. (priority high 2)
  122.  
  123. (priority normal 0)
  124.  
  125. (load |examples\trees.dat|)
  126.