implement interpreter and demo + bug fixes
- implement interpreter and demo - replace StandardError with appropriate subclasses - implement division - rewrite Polynomial.simplify()
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
module RubyAlgebra
|
||||
# Команда интерпретатора
|
||||
class Command
|
||||
attr_reader :type
|
||||
|
||||
def type
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
# Команда присвоения
|
||||
@@ -39,20 +44,29 @@ module RubyAlgebra
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def type
|
||||
:assignment
|
||||
end
|
||||
end
|
||||
|
||||
# Команда вывода на экран
|
||||
class DisplayCommand < Command
|
||||
attr_reader :polynomial
|
||||
attr_reader :item
|
||||
|
||||
def initialize(polynomial)
|
||||
@polynomial = polynomial
|
||||
def initialize(item)
|
||||
@type = :display
|
||||
@item = item
|
||||
end
|
||||
|
||||
def to_s
|
||||
result = "Display command: "
|
||||
result += @polynomial.to_s
|
||||
result += @item.to_s
|
||||
result
|
||||
end
|
||||
|
||||
def type
|
||||
:display
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user