/
main.php
59 lines (50 loc) · 1.23 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require_once('inout.php');
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;
}
}
if ($argc > 3) {
echo "Too much argument in command line\n";
}
elseif ($argc < 3) {
echo "Too few argument in command line\n";
}
else {
// преобразовать каждое выражение
$tree1 = process_each_expression($argv[1], "tree1.gv");
$tree2 = process_each_expression($argv[2], "tree2.gv");
// сравнение
if ($tree1 !== null && $tree2 !== null) {
$file = fopen("result.txt", "w");
if (is_tree_equal($tree1, $tree2)) {
fwrite($file, 'Expression equals');
}
else {
fwrite($file, 'Epression NOT equals');
}
fclose($file);
}
}
?>