/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/operator/add_operator_token.vala

  • Committer: Gustav Hartvigsson
  • Date: 2020-06-07 18:48:24 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20200607184824-jf14f7a1b1di2i2q
* Initial code - far from done

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace VQDR.Expression {
 
2
  
 
3
  class AddOperatorToken : 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) {
 
9
        return PRIO_UNARY;
 
10
      } else {
 
11
        return PRIO_ADDICTIVE;
 
12
      }
 
13
    } protected construct set {}} // set_priority will have no effect.
 
14
    
 
15
    construct {
 
16
      mandatory_num_child = 2;
 
17
      
 
18
    }
 
19
    
 
20
    protected AddOperatorToken (int position) {
 
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
        
 
45
        result_value = l_child.result_value + l_child.result_value;
 
46
        result_max_value = l_child.result_max_value + l_child.result_max_value;
 
47
        result_min_value = l_child.result_min_value + l_child.result_min_value;
 
48
        reorder_max_min_values ();
 
49
        result_string = l_child.result_string + "+" + l_child.result_string;
 
50
      }
 
51
    }
 
52
    
 
53
  }
 
54
  
 
55
  
 
56
}