public function convert($parent)
 {
     $this->convert_each_childrens();
     //---
     if (get_class($this->children) == 'qtype_correctwriting_unary_minus_operator') {
         $this->ptonewchild = $this->children->children;
         return;
     }
     //--
     if (get_class($this->children) == 'qtype_correctwriting_operand' && $this->children->number !== null) {
         $this->children->number = -$this->children->number;
         $this->children->name = strval($this->children->number);
         $this->children->treeinstring = $this->children->name;
         $this->ptonewchild = $this->children;
         return;
     }
     //--
     if (get_class($this->children) == 'qtype_correctwriting_plus_operator') {
         for ($i = 0; $i < count($this->children->childrens); $i++) {
             $t = new qtype_correctwriting_unary_minus_operator();
             $t->children = $this->children->childrens[$i];
             $this->children->childrens[$i] = $t;
             $t->calculate_tree_in_string();
         }
         $this->children->calculate_tree_in_string();
         $this->ptonewchild = $this->children;
         return;
     }
 }
Example #2
0
 /** 
  * Проверка можно ли два операнды операции сравнения одинаковые
  * 
  * \param [in] one операнд первой операции сравнения
  * \param [in] two операнд второй операции сравнения
  *
  * \return true если они одинаковые и можно преобразовать в вид >= или <=, в противном случае false
  */
 public function is_childs_same($one, $two)
 {
     // проверка левого сына a и b
     if (is_tree_equal($one->left, $two->left)) {
         return TRUE;
     }
     // проверка левого сына а с обратном знаком
     $tmp = new qtype_correctwriting_unary_minus_operator();
     // создать унарный минус
     $tmp->children = clone $one->left;
     // преобразовать новый узел
     $tmp->ptonewchild = null;
     $tmp->convert(tmp);
     while ($tmp->ptonewchild !== null) {
         $tmp = $tmp->ptonewchild;
         $tmp->ptonewchild = null;
         $tmp->convert(tmp);
     }
     // сравнение сына a с обратном знаком
     return is_tree_equal($tmp, $two->left);
 }
Example #3
0
 public function convert($parent)
 {
     // преобразовать каждый сын
     $this->convert_each_childrens();
     // перенести операнд влево
     $tmp = new qtype_correctwriting_plus_operator();
     $t = new qtype_correctwriting_unary_minus_operator();
     $t->children = $this->right;
     $t->calculate_tree_in_string();
     array_push($tmp->childrens, $this->left);
     array_push($tmp->childrens, $t);
     $this->left = $tmp;
     $this->right = new qtype_correctwriting_operand("0", 0);
     //var_dump($this->left);
     // преобразовать новый сын
     $this->left->ptonewchild = null;
     $this->left->convert($this);
     while ($this->left->ptonewchild !== null) {
         $this->left = $this->left->ptonewchild;
         $this->left->ptonewchild = null;
         $this->left->convert($this);
     }
     $this->left->calculate_tree_in_string();
 }