/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
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
namespace VQDR.Expression {
  
  class AddOperatorToken : OperatorToken, UnaryOperator {
    
    public override bool is_unary {get; set; default = false;}
    
    public override int priority {protected get {
      if (is_unary) {
        return Prio.UNARY;
      } else {
        return Prio.ADDICTIVE;
      }
    } protected construct set {}} // set_priority will have no effect.
    
    construct {
      mandatory_num_child = 2;
      
    }
    
    public AddOperatorToken (int position) {
      base (position);
    }
    
    public override void evaluate_self (Context instance) throws GLib.Error {
      Token r_child = get_right_child (),
            l_child = get_left_child ();
       
      if (r_child == null || l_child == null) {
          var sb = new StringBuilder ("(AddOperationToken) Missing ");
          if (r_child == null) {
            sb.append ("left "); 
          } else if (l_child == null) {
            sb.append ("right ");
          } else {
            sb.append ("both left and right ");
          }
          sb.append ("tokens.");
          throw new VQDR.Common.EvaluationError.MISSING_TOKEN (sb.str);
        }
       
      if (is_unary) {
        l_child.evaluate (instance);
        r_child.evaluate (instance);
        
        result_value = l_child.result_value.add (l_child.result_value);
        result_max_value = l_child.result_max_value.add (l_child.result_max_value);
        result_min_value = l_child.result_min_value.add (l_child.result_min_value);
        reorder_max_min_values ();
        result_string = l_child.result_string + "+" + l_child.result_string;
      }
    }
    
  }
  
  
}