Welcome to Python Command Line Interpreter v2.0. This version will evaluate valid Python mathematical expressions. Method calls (like Print("x")) are not supported. Enter an expression followed by Enter (use Left-Arrow for Backspace). Arithmetic operators supported: +, -, *, /, //, %, ** Assignment operators supported: =, +=, -=, *=, /=, //=, %=, **= Comparison operators supported: ==, !=, >, >=, <, <= Logical operators supported: and, or, not Unary operators supported: +x, -x Standard Python Operator Precedence (including Parenthesis) is followed to best of my knowledge. Whitespace is optional. Variable assignment and retrieval is supported. Strings and Lists are now supported. A sample session would look like this: >>> 1+2*3+4 11 >>> (1+2) * (3+4) 21 >>> x=8**2 >>> y=8%3 >>> x + y 66 >>> y > x False >>> z = [2, 4, 6] >>> z[0] + z[2] 8 >>> Q = [True, False] >>> not Q[1] True >>> 2**3 > 8 False >>> Enter an empty Statement to display the Variables Table. Enter again to hide it. Click the Green Flag to clear the screen, clear the variable table and start a new session. This is a work in progress. Feedback is more than welcome. Thanks.
This is based on an online blog: "Let's Build A Simple Interpreter" by Ruslan Spivak. I started writing it in Python (Yes. A Python interpreter written in Python seems a little redundant, but it is a good exercise), then wondered if I could port the algorithms over to Scratch. One of the hurdles is the fact that Scratch has no "Functions" to return a value directly so I write to "Global" variables to return results. The other problem is, some of the functions need to be called recursively (overwriting both temporary and output vars). To handle this, I use a "Stack" to "Push" and Pop" vars as needed. I'm happy with the results so far. This is a work in progress. Feedback is more than welcome.