/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/multiply_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 MultiplyOperatorToken : OperatorToken {
 
4
    
 
5
    construct {
 
6
      mandatory_num_child = 2;
 
7
      priority = PRIO_MULTIPLICATIVE;
 
8
    }
 
9
    
 
10
    protected MultiplyOperatorToken (int position) {
 
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
      var sb = new GLib.StringBuilder ("(");
 
22
      
 
23
      // We check the precidence of the token, and inclose the value if
 
24
      // it has a lower precidence than multiply, if it is, we enclose it in a
 
25
      // praranthesis.
 
26
      if (l_child.priority > 0 && l_child.priority < priority) {
 
27
        sb.append ("(").append (l_child.result_string).append (")");
 
28
        //l_child.result_string = "(" + l_child.result_string + ")";
 
29
      } else {
 
30
        sb.append (l_child.result_string);
 
31
      }
 
32
      
 
33
      sb.append ("*");
 
34
      
 
35
      // We do the same with the othre child.
 
36
      if (r_child.priority > 0 && r_child.priority < priority) {
 
37
        sb.append ("(").append (r_child.result_string).append (")");
 
38
        //r_child.result_string = "(" + r_child.result_string + ")";
 
39
      } else {
 
40
        sb.append (r_child.result_string);
 
41
      }
 
42
      
 
43
      sb.append (")");
 
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 = sb.str;
 
50
       
 
51
    }
 
52
    
 
53
  }
 
54
  
 
55
  
 
56
}