/vqdr/trunk

To get this branch, use:
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 SubtractOperatorToken : OperatorToken, UnaryOperator {
4
    
5
    public override bool is_unary {get; set; default = false;}
6
    
7
    public override int priority {protected get {
8
      if (is_unary) {
14 by Gustav Hartvigsson
* Use enum instead of static values for the priority of operations.
9
        return Prio.UNARY;
1 by Gustav Hartvigsson
* Initial code - far from done
10
      } else {
14 by Gustav Hartvigsson
* Use enum instead of static values for the priority of operations.
11
        return Prio.ADDICTIVE;
1 by Gustav Hartvigsson
* Initial code - far from done
12
      }
13
    } protected construct set {}} // set_priority will have no effect.
14
    
15
    construct {
16
      mandatory_num_child = 2;
17
      
18
    }
19
    
11 by Gustav Hartvigsson
* FastNumber:
20
    public SubtractOperatorToken (int position) {
1 by Gustav Hartvigsson
* Initial code - far from done
21
      base (position);
22
    }
23
    
24
    public override void evaluate_self (Context instance) throws GLib.Error {
25
      Token r_child = get_right_child (),
26
           l_child = get_left_child ();
27
           
28
      if (r_child == null || l_child == null) {
29
        var sb = new StringBuilder ("(AddOperationToken) Missing ");
30
        if (r_child == null) {
31
          sb.append ("left "); 
32
        } else if (l_child == null) {
33
          sb.append ("right ");
34
        } else {
35
          sb.append ("both left and right ");
36
        }
37
        sb.append ("tokens.");
38
        throw new VQDR.Common.EvaluationError.MISSING_TOKEN (sb.str);
39
      }
40
      
41
      if (is_unary) {
42
        l_child.evaluate (instance);
43
        r_child.evaluate (instance);
44
        
12.1.1 by Gustav Hartvigsson
* Switch to using FastNumber instead of something else.
45
        result_value = l_child.result_value.subtract (l_child.result_value);
46
        result_max_value = l_child.result_max_value.subtract (l_child.result_max_value);
47
        result_min_value = l_child.result_min_value.subtract (l_child.result_min_value);
1 by Gustav Hartvigsson
* Initial code - far from done
48
        reorder_max_min_values ();
49
        result_string = l_child.result_string + "-" + l_child.result_string;
50
      }
51
    }
52
  }
53
}