Calculator of combinated operations using integers.
The algorithm reads the input from the text file "proves.txt". You can use parenthesis () for priority, and the operators + - * / % ^ are available. Write your query expressions in a text file and execute the program. The algorithm will show the results in the standard output.
The Calculator works in the same way as a compiler, as it has severals phases to treat an operation:
- Check that all symbols in the entrance file are correct
- Check that the parenthesys make sense, being the redundant parenthesis accepted by the algorithm.
- Check that the meaning of the operations is okay, having every symbol separated by another with a number.
- A recursive process starts, that digests the expression using recursivity. On every iteration:
- Parenthesis are deleted.
- The operation to calcule is selected.
- Due to recursion two things can happen:
- One or two recursive calls are made to split the expression in smaller parts.
- An operation of one single operator is done (e.g. 3+5 ), and the result is returned to the calling function, returning from the recursive call.
(56*2+3)^2%2
2^(2+5)/2^2
5*4+1*4*6+(3*4+2*5*(4+2/1))
5*(4+2+3)*4*5+3*(2-2)
(((10+2)+5)+5)*(20-2)
(20-2)*(((10+2)+5)+5)
(3*(10+2))+((5+4)*(20-2))
- You can also use the calculator to check if an arithmeetical expression is correct.
You can find more documentation in the coments of the C code and in the "Documentació" folder of the repository, in catalan.