Class: BracketNotation::Evaluator
- Inherits:
-
Object
- Object
- BracketNotation::Evaluator
- Defined in:
- lib/bracket_notation/evaluator.rb
Overview
This class takes a list of Token instances and evaluates them. The result is an abstract tree representation of the syntax of the original string fed to the parser.
Defined Under Namespace
Classes: EvaluationError
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
-
#evaluate ⇒ Object
Evaluates a bracketed phrase and returns the Evaluation instance that represents the phrase.
-
#initialize(input) ⇒ Evaluator
constructor
Saves the token list for evaluation.
Constructor Details
#initialize(input) ⇒ Evaluator
Saves the token list for evaluation.
41 42 43 44 45 |
# File 'lib/bracket_notation/evaluator.rb', line 41 def initialize(input) @input = input @token_index = -1 @root = nil end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
34 35 36 |
# File 'lib/bracket_notation/evaluator.rb', line 34 def input @input end |
Instance Method Details
#evaluate ⇒ Object
Evaluates a bracketed phrase and returns the Evaluation instance that represents the phrase.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bracket_notation/evaluator.rb', line 49 def evaluate return @root unless @root.nil? token = next_token unexpected_token_error if token.type != Token::LBRACKET @root = evaluate_phrase unexpected_token_error if next_token.type != Token::EOL return @root end |