Skip to content

Commit

Permalink
Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
metacritical committed Mar 21, 2013
1 parent 800bb9b commit a432596
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/io/tokens.rb
Expand Up @@ -13,7 +13,7 @@ module Io
:MINUS, :ASTERISK, :MODULUS, :SLASH, :AND, :OR, :COMPARISON, :NOT_EQUALS, :NOT, :LESSTHAN_EQUALS, :GREATERTHAN_EQUALS,
:LESSTHAN, :GREATERTHAN, :SEMICOLON, :COMMA, :GETTER_SETTER, :SETSLOT, :UPDATESLOT, :EXPONENT
]

class Token
attr_accessor :type , :value , :line , :column
def initialize(token)
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rb
Expand Up @@ -71,6 +71,7 @@ def expression(type=nil)

def addition
check_type(current_token)
node = { :PLUS => AST::Addition }
if current_token.type == :PLUS
AST::Addition.new({:left => tree_stack.pop, :right => read_token})
else
Expand All @@ -81,6 +82,7 @@ def addition

def subtraction
check_type(current_token)
node = { :MINUS => AST::Subtraction }
if current_token.type == :MINUS
AST::Subtraction.new({:left => tree_stack.pop, :right => read_token})
else
Expand All @@ -91,11 +93,9 @@ def subtraction

def multiplication
check_type(current_token)
node = { :ASTERISK => AST::Multiplication }
if current_token.type == :ASTERISK
AST::Multiplication.new({:left => tree_stack.pop, :right => read_token})
else
read_token
AST::Multiplication.new({:left => look_behind, :right => read_token})
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/spec_helper.rb
Expand Up @@ -72,7 +72,7 @@ def simple_code
end

def simple_addition
%Q{1 + 2 * 3 - 5} #- 4 + 5 + 6 - 7}
%Q{1 + 2 * 3} #- 4 + 5 + 6 - 7}
end

=begin
Expand Down

0 comments on commit a432596

Please sign in to comment.