Web Python Interpreter
summary

This is a project to interpret python script inside browser.
The difficult part is to interrupt the running at anytime you want, since javascript does not support multi-threading.
Jison parser and CodeMirror are used.

operation

Click on top left blue button to run your code. While running, the button changed to orange, and you can stop the code by clicking on the button.
Currently, you cannot add Class yet, and """ symbol is not supported.
algorithm

Stop at anytime
When I perform semantic action to the AST, use setInterval(resolve, 0) to run a step in a loop or a function call. That makes javascript to stop the code for a second and see if interruption or other operation is needed.
When interruption happens, it changes a global state variable, and the resolve function in the setInterval will look at the globla state variable, and break if it is changed to interruption.

Indention to block structore
There is a state variable in lexer indicating if the lexer is in indenting state.
If it is, the lexer will record spaces it reads until it meet the first non-space, non-tab and non-newline token. Then the indenting state is ended.
In the Jison (Parser), at the end of a statement, the indenting state is enabled again.
When the indenting ends, lexer will see if the number of indention is different from the previous statement. If it is true, lexer will produce several { or } tokens, depends on the difference of the current indention and previous indention.