Discussion about this post

User's avatar
Lex Spoon's avatar

That is a lovely trip down memory lane to see that BASIC program on the top. I have my old MC-10 in a corner, and your bubble sort program looks like something that would be right at home on it.

Now, the interpreter itself, that hardly looks like BASIC at all! :) Declared variables? Functions??

Anyway, kudos and congrats.

Oh, and as a random comment, I think it is most logical to consider unary - and exponentiation as being at the same precedence level. If you say - is lower precedence, then you cannot parse `4^-x`, because you can't use a lower-precederence operator inside a higher-precedence one without parentheses. It all works out if you say that they are the same precedence and will resolve ambiguities from right to left.

There are some great comments on [this Stack Exchange comment](https://math.stackexchange.com/a/3047801) that strangely only has two upvotes. It's a bit of syntax lore that seems to be poorly known. I've certainly messed it up myself.

The comment has some test cases that you could try out. For example,if the input is `4^-1^2`, what does your interpreter give back? You want it to go right to left, i.e. `4^(-(1^2))`, which gives back `0.25`. You don't want it to evaluate as `4^((-1)^2)` which would be `4`.

Expand full comment
1 more comment...

No posts

Ready for more?