pulled assignment as special case from the operators

This commit is contained in:
Torsten Ruger
2014-06-24 19:33:21 +03:00
parent 58064637cb
commit 0ed11b507f
9 changed files with 61 additions and 39 deletions

View File

@ -16,4 +16,22 @@ module Ast
"#{left} #{operator} #{right}"
end
end
end
class AssignmentExpression < Expression
attr_reader :left, :right
def initialize left, right
@left, @right = left, right
end
def attributes
[:left, :right]
end
def inspect
self.class.name + ".new(" + left.inspect + "," + right.inspect + ")"
end
def to_s
"#{left} = #{right}"
end
end
end

View File

@ -65,7 +65,12 @@ module Parser
end
rule(l: simple(:l), o: simple(:o) , r: simple(:r)) do
Ast::OperatorExpression.new( o.to_s.strip , l ,r)
op = o.to_s.strip
if op == "="
Ast::AssignmentExpression.new( l ,r)
else
Ast::OperatorExpression.new( op , l ,r)
end
end
#modules and classes are understandibly quite similar Class < Module