/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 AddOperatorToken : OperatorToken, UnaryOperator {
4
    
5
    public override bool is_unary {get; set; default = false;}
6
    
54 by Gustav Hartvigsson
More work torwards inperementing the parser.
7
    public override Token.Prio priority {protected get {
1 by Gustav Hartvigsson
* Initial code - far from done
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
    
52.1.3 by Gustav Hartvigsson
int -> int32
20
    public AddOperatorToken (int32 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 ");
23 by Gustav Hartvigsson
* Added DiceOperatiorToken
30
          if (l_child == null && r_child == null) {
31
            sb.append ("both left and right ");
32
          } else if (r_child == null) {
1 by Gustav Hartvigsson
* Initial code - far from done
33
            sb.append ("left "); 
23 by Gustav Hartvigsson
* Added DiceOperatiorToken
34
          } else {
1 by Gustav Hartvigsson
* Initial code - far from done
35
            sb.append ("right ");
36
          }
37
          sb.append ("tokens.");
64 by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming.
38
          throw new EvaluationError.MISSING_TOKEN (sb.str);
1 by Gustav Hartvigsson
* Initial code - far from done
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.add (l_child.result_value);
57 by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns.
46
        result_max_value = l_child.result_max_value
47
          .add (l_child.result_max_value);
48
        result_min_value = l_child.result_min_value
49
          .add (l_child.result_min_value);
1 by Gustav Hartvigsson
* Initial code - far from done
50
        reorder_max_min_values ();
51
        result_string = l_child.result_string + "+" + l_child.result_string;
52
      }
53
    }
54
    
55
  }
56
  
57
  
58
}