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
  @symbol_queue = []
end

Instance Method Details

#runObject



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

def run
  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)
  end
  ParseSuccessResult.new(node_stack.first)
end