Class: Keisanjaku::Parser

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

Constant Summary collapse

FUNCTIONS =
%w[sqrt cbrt sin cos tan log].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Parser

Returns a new instance of Parser.



19
20
21
22
# File 'lib/keisanjaku/parser.rb', line 19

def initialize(input)
  @chars = input.to_s.each_char.to_a
  @index = 0
end

Class Method Details

.parse(input) ⇒ Object



33
34
35
# File 'lib/keisanjaku/parser.rb', line 33

def self.parse(input)
  new(input).parse
end

Instance Method Details

#parseObject



24
25
26
27
28
29
30
31
# File 'lib/keisanjaku/parser.rb', line 24

def parse
  skip_space
  node = parse_expr
  skip_space
  raise_error("unexpected token '#{peek}'") unless eof?

  node
end