Quote:
... to implement such a functionality probably will require hundreds lines of code - parsing numbers, signs, operator precedence and of course testing and error handling.
Yes, it would.
Unfortunately, that's because it's a complex project - to expand on what Rick has said, you need to do several things:
1) Verify the entered expression is valid.
2) Break the expression into operators and operands
3) Identify the unknown.
4) Reformat the expression so that the unknown is alone on one side of the equals sign evaluating "chunks" as you go:
30=2x+4
2x=30-4
2x=26
x=26/2
x=13
Exactly the same way you would if you were doing it manually.
This may help you get started:
How to Write Code to Solve a Problem, A Beginner's Guide[
^]
But ... do note that your example
30 = (x + 38)%4
fails the first step as there is no unique solution: you cannot "reverse" modulus operators to get back the original input as it discards info. So you can't get from
30 = (x + 38)%4
to
(x + 38) = 30 <any operator> 4
as you can with the paired operators like add/subtract and mutiply/divide.