Class: ExpressionParser::Parser

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

Instance Method Summary collapse

Instance Method Details

#parse(input) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/expression_parser/parser.rb', line 5

def parse(input)
  @lexer = Lexer.new(input)

  expression_value = expression
  token = @lexer.get_next_token
  if token.kind == Token::End
	expression_value
  else
	case token.kind
    when Token::GThan
	  expression_value > expression ? 1 : 0
	when Token::LThan
	  expression_value < expression ? 1 : 0
	when Token::Equal
	  expression_value == expression ? 1 : 0
	when Token::NotEqual
	  expression_value != expression ? 1 : 0
	when Token::GThanE
	  expression_value >= expression ? 1 : 0
	when Token::LThanE
	  expression_value <= expression ? 1 : 0
	else
	  raise 'End expected'
	end
  end
end