expression_debug.cpp
1.59 KB
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
60
61
#include <poincare/context.h>
#include <poincare/expression.h>
#include <poincare/symbol.h>
#include <iostream>
void print_expression(const Expression * e, int indentationLevel) {
if (indentationLevel>0) {
for (int i=0; i<indentationLevel-1; i++) {
std::cout << " ";
}
std::cout << "|-";
}
Context context;
switch (e->type()) {
case Expression::Type::Addition:
std::cout << "Addition";
break;
case Expression::Type::Cosine:
std::cout << "Cosine";
break;
case Expression::Type::Float:
std::cout << "Float()";
break;
case Expression::Type::Integer:
std::cout << "Integer(";
std::cout << e->approximate(context);
std::cout << ")";
break;
case Expression::Type::Fraction:
std::cout << "Fraction";
break;
case Expression::Type::Matrix:
std::cout << "Matrix";
break;
case Expression::Type::Parenthesis:
std::cout << "Parenthesis";
break;
case Expression::Type::Power:
std::cout << "Power";
break;
case Expression::Type::Product:
std::cout << "Product";
break;
case Expression::Type::Sine:
std::cout << "Sine";
break;
case Expression::Type::Subtraction:
std::cout << "Subtraction";
break;
case Expression::Type::Symbol:
std::cout << "Symbol(" << ((Symbol*)e)->name() << ")";
break;
case Expression::Type::Tangent:
std::cout << "Tangent";
break;
}
std::cout << std::endl;
for (int i=0; i<e->numberOfOperands(); i++) {
print_expression(e->operand(i), indentationLevel+1);
}
}