Class: ShuntingYard::Parser
- Inherits:
-
Object
- Object
- ShuntingYard::Parser
- Extended by:
- Forwardable
- Defined in:
- lib/shunting_yard/parser.rb
Instance Attribute Summary collapse
-
#interpreter ⇒ Object
Returns the value of attribute interpreter.
-
#lexer ⇒ Object
Returns the value of attribute lexer.
Instance Method Summary collapse
- #evaluate(input) ⇒ Object
-
#initialize(lexer: nil, interpreter: nil) ⇒ Parser
constructor
A new instance of Parser.
- #to_rpn(input) ⇒ Object
Constructor Details
#initialize(lexer: nil, interpreter: nil) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 |
# File 'lib/shunting_yard/parser.rb', line 10 def initialize(lexer: nil, interpreter: nil) @lexer = lexer || Lexer.new @interpreter = interpreter || Interpreter.new end |
Instance Attribute Details
#interpreter ⇒ Object
Returns the value of attribute interpreter.
8 9 10 |
# File 'lib/shunting_yard/parser.rb', line 8 def interpreter @interpreter end |
#lexer ⇒ Object
Returns the value of attribute lexer.
7 8 9 |
# File 'lib/shunting_yard/parser.rb', line 7 def lexer @lexer end |
Instance Method Details
#evaluate(input) ⇒ Object
18 19 20 21 |
# File 'lib/shunting_yard/parser.rb', line 18 def evaluate(input) rpn_tokens = to_rpn(input) interpreter.evaluate(rpn_tokens) end |
#to_rpn(input) ⇒ Object
23 24 25 26 |
# File 'lib/shunting_yard/parser.rb', line 23 def to_rpn(input) tokens = tokenize(input) interpreter.to_rpn(tokens) end |