Reputation: 23
Can someone give me a code of example for Turing Machine Calculator
which can accept these inputs
30+25x3-2/5=
and the output is 104.6
this calculator cant accept these input
3+52-2
43+1=12
0+12+1=
2+0+x2=
1x02=
+2+3=
x19x1=
12x2x=
Upvotes: 0
Views: 1163
Reputation: 443
This sounds like a homework assignment, so I won't give you the code, but in general what you'll need to do is parse the input into a tree structure based on order of operations, and then resolve it recursively. There are several ways to achieve this but it is likely, if this is a homework assignment, that your professor has recently talked about the specific way he or she would like you to solve it.
You will essentially be reimplementing the *nix "bc" program. The GNU implementation is free software, and you can get the code to inspect here: https://www.gnu.org/software/bc/
Upvotes: 2