Class: YABFI::Lexer

Inherits:
Consumer show all
Defined in:
lib/yabfi/lexer.rb

Overview

This module consumes tokens produced by the Parser and produces an unoptimized syntax tree.

Constant Summary collapse

DISPATCH_TABLE =

This Hash maps tokens to method names to optimize the performance of the lexer.

{
  loop: :while_loop,
  succ: :change_value,
  pred: :change_value,
  next: :change_pointer,
  prev: :change_pointer,
  get: :get,
  put: :put
}

Constants inherited from Consumer

Consumer::EndOfInput, Consumer::Unsatisfied

Instance Attribute Summary

Attributes inherited from Consumer

#tokens

Class Method Summary collapse

Methods inherited from Consumer

#advance, #attempt, #consume_index, #end_of_input?, #eq, #initialize, #many, #many_one, #one_of, #peek, #satisfy, #seek

Constructor Details

This class inherits a constructor from YABFI::Consumer

Class Method Details

.run!(tokens) ⇒ Array<Object>

Run the lexer on the given tokens.

Parameters:

  • tokens (Array<Symbol>)

    the input tokens.

Returns:

  • (Array<Object>)

    the lexed syntax tree.

Raises:

  • (Consumer::Error)

    when the lexing fails.



22
23
24
# File 'lib/yabfi/lexer.rb', line 22

def self.run!(tokens)
  new(tokens).send(:run!)
end