Class: Dhaka::ParserRun

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(grammar, start_state, token_stream) ⇒ ParserRun

Returns a new instance of ParserRun.



4
5
6
7
8
9
10
# File 'lib/parser/parser_run.rb', line 4

def initialize(grammar, start_state, token_stream)
  @grammar = grammar
  @node_stack = []
  @state_stack = [start_state]
  @token_stream = token_stream
  @current_token_index = 0
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
# File 'lib/parser/parser_run.rb', line 12

def run
  for_each_token_with_end do
    error = execute_action current_token.grammar_symbol.name
    return error if error
    node_stack << ParseTreeLeafNode.new(current_token)
    @current_token_index += 1
  end
  ParseSuccessResult.new(node_stack[0])
end