Class: Dhaka::ParserRun

Inherits:
Object
  • Object
show all
Defined in:
lib/dhaka/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/dhaka/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
  @symbol_queue = []
end

Instance Method Details

#runObject



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

def run
  tokenize_result = token_stream.each do |token|
    @current_token = token
    @symbol_queue << @current_token.symbol_name
    error = execute_actions
    return error if error
    node_stack << ParseTreeLeafNode.new(@current_token)
    state_stack.last
  end
  return tokenize_result if TokenizerErrorResult === tokenize_result
  ParseSuccessResult.new(node_stack.first) if node_stack.first.head_node?
end