Example #1
0
 /** 
  * Преобразовать операций сравнений > (<) и == в вид >= (<=)
  */
 public function reduce_compare()
 {
     $vtemp = array();
     // временной вектор сыновей
     // нахождение сравнения можно сокращать
     for ($i = 0; $i < count($this->childrens); $i++) {
         if ($this->childrens[$i] !== null) {
             $isAdd = TRUE;
             // флаг : добавить текущий узел в временной вектор
             $lnode;
             // указатель на узел сравнение
             $enode;
             // указатель на узел равенства
             for ($j = $i + 1; $j < count($this->childrens) && $isAdd; $j++) {
                 $isComp = FALSE;
                 // флаг: нашлось ли узлы для сокращения
                 if (get_class($this->childrens[$i]) == 'qtype_correctwriting_greater_operator' && get_class($this->childrens[$j]) == 'qtype_correctwriting_equal_operator') {
                     $isComp = TRUE;
                     $lnode = $this->childrens[$i];
                     $enode = $this->childrens[$j];
                 } else {
                     if (get_class($this->childrens[$i]) == 'qtype_correctwriting_equal_operator' && get_class($this->childrens[$j]) == 'qtype_correctwriting_greater_operator') {
                         $isComp = true;
                         $lnode = $this->childrens[$j];
                         $enode = $this->childrens[$i];
                     } else {
                         if (get_class($this->childrens[$i]) == 'qtype_correctwriting_less_operator' && get_class($this->childrens[$j]) == 'qtype_correctwriting_equal_operator') {
                             $isComp = true;
                             $lnode = $this->childrens[$i];
                             $enode = $this->childrens[$j];
                         } else {
                             if (get_class($this->childrens[$i]) == 'qtype_correctwriting_equal_operator' && get_class($this->childrens[$j]) == 'qtype_correctwriting_less_operator') {
                                 $isComp = true;
                                 $lnode = $this->childrens[$j];
                                 $enode = $this->childrens[$i];
                             }
                         }
                     }
                 }
                 // проверка можно ли сокращать
                 if ($isComp && $this->is_childs_same($lnode, $enode)) {
                     // создать новый узел
                     if (get_class($lnode) == 'qtype_correctwriting_less_operator') {
                         $tmp = new qtype_correctwriting_less_equal_operator();
                     } else {
                         $tmp = new qtype_correctwriting_greater_equal_operator();
                     }
                     // присваивать значения
                     $tmp->left = $lnode->left;
                     $tmp->right = $lnode->right;
                     $isAdd = FALSE;
                     $tmp->calculate_tree_in_string();
                     // добавить в временной вектор сыновей
                     array_push($vtemp, $tmp);
                     // удалить из вектора сыновей
                     $this->childrens[$i] = $this->childrens[$j] = null;
                 }
             }
             if ($isAdd) {
                 array_push($vtemp, $this->childrens[$i]);
             }
         }
     }
     // присваивать новые сыновья
     $this->childrens = $vtemp;
 }
Example #2
0
 public function convert($parent)
 {
     // преобразовать каждый сын
     $this->convert_each_childrens();
     // преобразовать в вид >=
     $tmp = new qtype_correctwriting_greater_equal_operator();
     $tmp->left = $this->right;
     $tmp->right = $this->left;
     $tmp->calculate_tree_in_string();
     $this->ptonewchild = $tmp;
 }