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:
2026-04-13 19:33:50 +03:00
parent f283d039c1
commit 1fff529e83
6 changed files with 221 additions and 99 deletions

View File

@@ -4,21 +4,27 @@
require 'bundler/setup'
require 'ruby_algebra'
puts 'RubyMaple © RubyMaple Creators, 2026. No rights reserved.'
print "RubyMaple © RubyMaple Creators, 2026. No rights reserved.\nPress Ctrl+D to quit.\n"
interp = RubyAlgebra::Interpreter.new
loop do
puts 'Введите формулу (пустая строка для выхода): '
inp = $stdin.gets.chomp
exit if inp.empty?
begin
formula = RubyAlgebra::Parser.parse(inp)
rescue StandardError
puts 'Ошибка синтаксиса'
end
puts "Формула: #{formula}"
puts "Производная по x: #{formula.diff('x')}"
puts "Производная по y: #{formula.diff('y')}"
print '> '
inp = $stdin.gets
break if inp.nil?
value = formula.evaluate
puts "Числовое значение: #{value}" unless value.nil?
inp = inp.chomp
next if inp.empty?
begin
command = RubyAlgebra::Parser.parse_command(inp)
rescue StandardError => e
puts "Syntax error: #{e.message}"
next
end
begin
puts "< #{interp.execute(command)}"
rescue StandardError => e
puts "Calculation error: #{e.message}"
end
end
puts