start conditionals

This commit is contained in:
Torsten Ruger
2015-09-14 16:47:22 +03:00
parent 11a218449d
commit acf4046225
11 changed files with 225 additions and 119 deletions

View File

@ -59,9 +59,62 @@ module Ast
end
end
class TypedName < NameExpression
attr_reader :type
def initialize type , name
super(name)
@type = type.to_sym
end
def attributes
[:type, :name]
end
def inspect
"#{self.class.name}.new(#{type.inspect},#{name.inspect})"
end
def to_s
inspect
end
end
class VariableDefinition < TypedName
attr_reader :right
def initialize type , name , right
super(type , name)
@right = right
end
def attributes
super + [:right]
end
def inspect
self.class.name + ".new(" + type.inspect + "," + name.inspect + "," + right.inspect + ")"
end
def to_s
inspect
end
end
class VariableExpression < NameExpression
end
class AssignmentExpression < NameExpression
attr_reader :right
def initialize name, right
super(name)
@right = right
end
def attributes
super + [:right]
end
def inspect
self.class.name + ".new(" + name.inspect + "," + right.inspect + ")"
end
def to_s
"#{left} = #{right}"
end
end
class ModuleName < NameExpression
end

View File

@ -1,5 +1,5 @@
module Ast
class OperatorExpression < Expression
attr_reader :operator, :left, :right
@ -10,28 +10,11 @@ module Ast
[:operator, :left, :right]
end
def inspect
self.class.name + ".new(" + operator.inspect + ", " + left.inspect + "," + right.inspect + ")"
self.class.name + ".new(" + operator.inspect + ", " + left.inspect + "," + right.inspect + ")"
end
def to_s
"#{left} #{operator} #{right}"
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