bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
|
1
by Gustav Hartvigsson
* Initial code - far from done |
1 |
namespace VQDR.Expression { |
2 |
|
|
3 |
class DivideOperatorToken : OperatorToken { |
|
4 |
|
|
5 |
construct { |
|
6 |
mandatory_num_child = 2; |
|
|
14
by Gustav Hartvigsson
* Use enum instead of static values for the priority of operations. |
7 |
priority = Prio.MULTIPLICATIVE; |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
8 |
} |
9 |
|
|
|
11
by Gustav Hartvigsson
* FastNumber: |
10 |
public DivideOperatorToken (int position) { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
11 |
base (position); |
12 |
} |
|
13 |
|
|
14 |
public override void evaluate_self (Context instance) throws GLib.Error { |
|
15 |
Token r_child = get_right_child (), |
|
16 |
l_child = get_left_child (); |
|
17 |
|
|
18 |
l_child.evaluate (instance); |
|
19 |
r_child.evaluate (instance); |
|
20 |
|
|
21 |
// Division by zero is not somthing we want to do. |
|
22 |
// Black holes are bad. |
|
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
23 |
if (l_child.result_value.number == 0) { |
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
24 |
throw new Vee.MathError.DIVIDE_BY_ZERO |
|
33
by Gustav Hartvigsson
Added sudfolders to the tests folder for future use. |
25 |
("(DivideOperationToken) The left value is zero."); |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
26 |
} |
27 |
|
|
28 |
var sb = new GLib.StringBuilder ("("); |
|
29 |
|
|
30 |
// We check the precidence of the token, and inclose the value if |
|
31 |
// it has a lower precidence than multiply, if it is, we enclose it in a |
|
32 |
// praranthesis. |
|
|
54
by Gustav Hartvigsson
More work torwards inperementing the parser. |
33 |
if (l_child.priority > Prio.ASSIGNMENT && l_child.priority < priority) { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
34 |
sb.append ("(").append (l_child.result_string).append (")"); |
35 |
//l_child.result_string = "(" + l_child.result_string + ")"; |
|
36 |
} else { |
|
37 |
sb.append (l_child.result_string); |
|
38 |
} |
|
39 |
|
|
40 |
sb.append ("*"); |
|
41 |
|
|
42 |
// We do the same with the othre child. |
|
|
54
by Gustav Hartvigsson
More work torwards inperementing the parser. |
43 |
if (r_child.priority > Prio.ASSIGNMENT && r_child.priority < priority) { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
44 |
sb.append ("(").append (r_child.result_string).append (")"); |
45 |
//r_child.result_string = "(" + r_child.result_string + ")"; |
|
46 |
} else { |
|
47 |
sb.append (r_child.result_string); |
|
48 |
} |
|
49 |
|
|
50 |
sb.append (")"); |
|
51 |
|
|
|
57
by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns. |
52 |
result_value = l_child.result_value |
53 |
.divide (l_child.result_value); |
|
54 |
result_max_value = l_child.result_max_value |
|
55 |
.divide (l_child.result_max_value); |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
56 |
reorder_max_min_values (); |
57 |
result_string = sb.str; |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
|
|
64 |
}
|