Class: Kalc::Runner
- Inherits:
-
Object
- Object
- Kalc::Runner
- Defined in:
- lib/kalc.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#grammar ⇒ Object
Returns the value of attribute grammar.
-
#interpreter ⇒ Object
Returns the value of attribute interpreter.
-
#transform ⇒ Object
Returns the value of attribute transform.
Instance Method Summary collapse
-
#initialize(debug = false) ⇒ Runner
constructor
A new instance of Runner.
- #reload ⇒ Object
- #run(expression) ⇒ Object
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
#ast ⇒ Object
Returns the value of attribute ast.
18 19 20 |
# File 'lib/kalc.rb', line 18 def ast @ast end |
#grammar ⇒ Object
Returns the value of attribute grammar.
15 16 17 |
# File 'lib/kalc.rb', line 15 def grammar @grammar end |
#interpreter ⇒ Object
Returns the value of attribute interpreter.
17 18 19 |
# File 'lib/kalc.rb', line 17 def interpreter @interpreter end |
#transform ⇒ Object
Returns the value of attribute transform.
16 17 18 |
# File 'lib/kalc.rb', line 16 def transform @transform end |
Instance Method Details
#reload ⇒ Object
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 |