add substitution and differentiation

This commit is contained in:
2026-04-13 19:58:40 +03:00
parent 1fff529e83
commit 037c34b38e
3 changed files with 31 additions and 12 deletions

View File

@@ -261,10 +261,17 @@ module RubyAlgebra
raise ParserError, "unexpected token #{n.type}, expected ="
end
n = tokenizer.next_token
unless n.type == :num || n.type == :plus || n.type == :minus
raise ParserError, "unexpected token #{n.type}, expected -, + or number"
end
if n.type == :plus || n.type == :minus
negative = true if n.type == :minus
n = tokenizer.next_token
end
unless n.type == :num
raise ParserError, "unexpected token #{n.type}, expected number"
end
substitutions[variable] = n.value
substitutions[variable] = if negative then -n.value else n.value end
end
n = tokenizer.next_token
unless n.type == :paren && n.closing == true