예제 #1
0
 /**
  * @dataProvider mydataProvider
  */
 public function test_convert($expr1, $expr2)
 {
     global $typeOfVars;
     $tree1 = build_tree($expr1, $typeOfVars);
     $tree2 = build_tree($expr2, $typeOfVars);
     $tree1->ptonewchild = null;
     $tree1->convert($tree1);
     while ($tree1->ptonewchild != null) {
         $tree1 = $tree1->ptonewchild;
         $tree1->ptonewchild = null;
         $tree1->convert($tree1);
     }
     $file = fopen("tree2.gv", "w");
     fwrite($file, "digraph {\n");
     print_tree_to_dot($file, $tree2);
     fwrite($file, '}');
     fclose($file);
     $tree2->ptonewchild = null;
     $tree2->convert($tree2);
     while ($tree2->ptonewchild != null) {
         $tree2 = $tree2->ptonewchild;
         $tree2->ptonewchild = null;
         $tree2->convert($tree2);
     }
     $file = fopen("tree1.gv", "w");
     fwrite($file, "digraph {\n");
     print_tree_to_dot($file, $tree1);
     fwrite($file, '}');
     fclose($file);
     $this->assertTrue(is_tree_equal($tree1, $tree2, TRUE));
     $tree1->delete_childrens();
     $tree2->delete_childrens();
     unset($tree1);
     unset($tree2);
 }
예제 #2
0
function process_each_expression($filename, $filegv)
{
    try {
        $exp = readExp($filename);
        $tree = build_tree($exp);
        // преобразовать
        $tree->ptonewchild = null;
        $tree->convert($tree);
        while ($tree->ptonewchild != null) {
            $tree = $tree->ptonewchild;
            $tree->ptonewchild = null;
            $tree->convert($tree);
        }
        // печать DOT файл
        $file = fopen($filegv, "w");
        fwrite($file, "digraph {\n");
        print_tree_to_dot($file, $tree);
        fwrite($file, '}');
        fclose($file);
        return $tree;
    } catch (Exception $e) {
        echo "In file {$filename}: " . $e->getMessage() . " \n";
        return null;
    }
}
예제 #3
0
/**
 * Печать дерево в формат DOT
 *
 * \param [in] file указатель на выходный файл
 * \param [in] curNode указатель на текущий узел
 * 
 */
function print_tree_to_dot($file, $curNode)
{
    static $globalid = 0;
    // следующий идентификатор для узлов
    $id = $globalid;
    // идентификатор для данный узла
    // инкремент общий индетификатор
    ++$globalid;
    // печать определение для данного узла
    if (is_a($curNode, 'qtype_correctwriting_operand')) {
        fwrite($file, $id . ' [label = ' . $curNode->name);
    } else {
        fwrite($file, $id . ' [label = "' . $curNode->get_label(get_class($curNode)) . '"');
    }
    fwrite($file, "]\n");
    // переход на сыновья
    if (is_subclass_of($curNode, 'qtype_correctwriting_one_dim_node')) {
        // унарный узел
        $next = $globalid;
        print_tree_to_dot($file, $curNode->children);
        fwrite($file, $id . ' -> ' . $next . "\n");
    } elseif (is_subclass_of($curNode, 'qtype_correctwriting_k_dim_node')) {
        // двоичной узел
        foreach ($curNode->childrens as $value) {
            $next = $globalid;
            print_tree_to_dot($file, $value);
            fwrite($file, $id . ' -> ' . $next . "\n");
        }
    } elseif (is_subclass_of($curNode, 'qtype_correctwriting_binary_node')) {
        // k-dim узел
        $next = $globalid;
        print_tree_to_dot($file, $curNode->left);
        fwrite($file, $id . ' -> ' . $next . "\n");
        $next = $globalid;
        print_tree_to_dot($file, $curNode->right);
        fwrite($file, $id . ' -> ' . $next . "\n");
    }
}