7 AnswersNew Answer
The requirements specifications did not touch on operator precedence, but I believe it would be a delighter for your interpreter to be able to calculate the statement according to proper norms, 5*4+3/2-1 (5*4)+(3/2)-1 From the syntax, the fictional language appears to be dynamically-typed. I'm assuming that the division between two integer values would result in an integer result, while the case where either or both parameters are floating-point values, would result in a floating-point value result. (5*4)+(3/2)-1 20+1-1 20 Of course, both of the above appears to be beyond the scope of this assignment.
If I were to judge, both are acceptable. 20.5 is obtained by carrying out floating-point operation when given two integer values as operands. This isn't wrong. Python, for instance, does that. While 10 is a bit unorthodox, we were not told/required to develop a language with operator precedence, and hence should not be disqualified as well.
Thanks Hatsy Rei
I'd say it's (5*4)+(3/2)-1 20+(3/2)-1 20+1.5-1 21.5-1 20.5 Makes more sense to me to make every number a float because the language doesn't offer explicit type casting.
Hatsy Rei what if interpreter is showing 20.5 or 10?
5*4+3/2-1 = (5*4)+(3/2)-1 = 20+1-1 =20. Note that 3/2 = 1, but 3.0/2.0=1.5