Class: Gloo::Expr::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/expr/expression.rb

Instance Method Summary collapse

Constructor Details

#initialize(engine, tokens) ⇒ Expression

Create the expression from a list of tokens.



18
19
20
21
22
23
24
25
# File 'lib/gloo/expr/expression.rb', line 18

def initialize( engine, tokens )
  @engine = engine
  @tokens = tokens
  @symbols = []
  @left = nil
  @right = nil
  @op = nil
end

Instance Method Details

#evaluateObject

Evaluate the expression and return the value.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gloo/expr/expression.rb', line 34

def evaluate
  identify_tokens

  @symbols.each do |sym|
    if sym.is_a? Gloo::Core::Op
      @op = sym
    elsif @left.nil?
      @left = sym
    else
      @right = sym
    end

    perform_op if @left && @right
  end

  return @left.value if @left.is_a? Gloo::Core::Literal
  return resolve_ref @left if @left.is_a? Gloo::Core::Pn

  return @left
end