From a4325960c0ead208a7bb69b889eec9017eca4ee0 Mon Sep 17 00:00:00 2001 From: Pankaj Doharey Date: Thu, 21 Mar 2013 23:18:12 +0530 Subject: [PATCH] Parser --- lib/io/tokens.rb | 2 +- src/parser.rb | 6 +++--- test/spec_helper.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/io/tokens.rb b/lib/io/tokens.rb index 4abae8a..42a2131 100644 --- a/lib/io/tokens.rb +++ b/lib/io/tokens.rb @@ -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) diff --git a/src/parser.rb b/src/parser.rb index 6eeec67..279f3d5 100644 --- a/src/parser.rb +++ b/src/parser.rb @@ -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 @@ -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 @@ -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 diff --git a/test/spec_helper.rb b/test/spec_helper.rb index ef55585..dcd1cc5 100644 --- a/test/spec_helper.rb +++ b/test/spec_helper.rb @@ -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