Class: Kalc::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/kalc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug = false) ⇒ Runner

Returns a new instance of Runner.



20
21
22
23
24
# File 'lib/kalc.rb', line 20

def initialize(debug = false)
  @debug = debug
  @log = Logger.new(STDOUT)
  load_environment
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



18
19
20
# File 'lib/kalc.rb', line 18

def ast
  @ast
end

#grammarObject

Returns the value of attribute grammar.



15
16
17
# File 'lib/kalc.rb', line 15

def grammar
  @grammar
end

#interpreterObject

Returns the value of attribute interpreter.



17
18
19
# File 'lib/kalc.rb', line 17

def interpreter
  @interpreter
end

#transformObject

Returns the value of attribute transform.



16
17
18
# File 'lib/kalc.rb', line 16

def transform
  @transform
end

Instance Method Details

#reloadObject



26
27
28
# File 'lib/kalc.rb', line 26

def reload
  load_environment
end

#run(expression) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/kalc.rb', line 30

def run(expression)
  if @debug
    @log.debug "Evaluating #{expression}"
    g = @grammar.parse_with_debug(expression)
  else
    g = @grammar.parse(expression)
  end
  @ast = @transform.apply(g)
  @interpreter.run(ast)
end