The demo is loaded with the Morris In-order traversal algorithm. To quickly see the functionality, start the project, select the third button, select the fifth button, and then select the second button. Code editor page: --Buttons (in order from left to right) ----upload: paste program into editor ----download: copy program from the editor ----build: compile program, and unhide the visualization button if the build compiles successfully ----clear: remove current program from the editor ----view: when the compiler is successful, go into the interactive BST view --Editor ----Scroll or use the scroll bar in the right corner to scroll the text ----Press "\" to delete, as scratch 3.0 cannot currently detect deletion ----The syntax is reminiscent of JavaScript, without keywords for variable declaration. All variables have global scope. The compiler supports supports the following: ------1) Control flow, such as if, while, break, and continue ------2) Logical and mathematical operations ------3) BST specific functions, such as reading and writing nodes Visual Interactive BST page: --Buttons (in order from left to right) ----back: return to the code editor ----play: run the compiled program ----play all at once: run the compiled program without delays between instructions ----reset BST values: set all nodes to "-1" --Interactive controls ----Scroll: zoom in and out ----Click and drag ------Background: pan the camera ------Node: select a node ----On a selected node: ------plus, left side: if the node has no left child, create a left child ------plus, right side: if the node has no right child, create a right child ------ minus, top right: if the node has node children, remove the node
Change log: Update v0.1.3 - Syntax highlighting is now feature complete, and the first character of keywords no longer changes colors occasionally. This feature will be revisited in the future for improvements with recoloring string changes - Reworked the BST rendered to ignore loops when calculating the layout. This should remove all BST related freezes. - Added support for turbowarp key sensing features. Update v0.1.2 - Improved quoted string coloring. With the current implementation it would require re-lexing the entire document, and needs to be reimplemented Update v0.1.1 - Fixed the first letter of strings being colored incorrectly - Strings surrounded by quotes are still broken Update v0.1.0 - Added dark mode - Added syntax highlighting. This feature is still in development, so strings and the first letters of some words may not be colored correctly. Update v0.0.10 - Added string caching, can save instructions, especially with the strings used in BST functions - Added error handling for unterminated expressions in the lexer Update v0.0.9 - Fixed implementation of freeing allocated temporary memory - Fixed assigning a variable to a variable - Binary operations now free allocated memory instead of directly overwriting accessed memory Update v0.0.8 - Temporarily reversed memory optimizations due to edge case that leads to a binary operation writing into a variable memory address. These changes will be reintroduced when string literal caching is implemented Update v0.0.7 - Functions now free all memory allocated after read, including the first argument. This saves a significant amount of space in memory - Functions which don't return a value no longer are given a temporary memory address. This also saves a significant amount of space in memory Update v0.0.6 - Functions now free the memory allocated after read - Reworked key detection Update v0.0.5 - Fixed unary operations negate and not - Negate now checks if it's applied to a literal and direct edits the instruction if so Update v0.0.4 - Reading from a variable no longer writes to a temp address, saving 1 instruction - Binary operations now check if their left child is an identity, and save an address accordingly - Expressions now cleanup additional temp memory allocations Update v0.0.3 - Logic and math operations now reuse temporary addresses, saving 3 memory addresses per operation - Reading a variable now writes to a temp address, which adds an instruction for each read but should save on memory - Added log(<value>) command for debugging - Temp addresses now start at index 1 instead of 10 Update v0.0.2 - Variable assignment now directly evaluates the expression to the variables memory addresses instead emitting a copy instruction. This saves 1 instruction per assignment - Temp address allocation still needs to be updated to reflect this change Notes: The compiler supports the following operations ( ) <math> ( ), where <math> is +,-,*,/,% ( ) <logical operator> ( ), where <logical operator> is &&, ||, !=, ==, <, > if( ) {} while( ) { } break: inside of while loops continue: inside of while loops Visualization specific functions getBstHead( ) getNode(<node>, <"left"|"right"|"value"|"name">) setNode(<node>, <"left"|"right"|"value"|"name">, <set to value>) markVar(<variable name>, <color>) log(<memory address>) Note that like Java, semicolons are required after expressions The toy computer supports the following operations function <BST function name> ...values... math <+,-,/,%,&&,||> <read address 1> <read address 2> <write address> equality <==, !=, "<", ">"> <read address 1> <read address 2> <write address> memory write <value> <write address> memory copy <copy address> <write address> jump <jump to address> jumpifnot <read address> <jump to address> Credits This uses a stripped down version of Griffpatch's 2.0 word processor Citations: Joseph M. Morris, Traversing binary trees simply and cheaply, Information Processing Letters, Volume 9, Issue 5, 1979, Pages 197-200, ISSN 0020-0190, https://doi.org/10.1016/0020-0190(79)90068-1. Christoph Buchheim, Michael Jünger, and Sebastian Leipert. 2002. Improving Walker's Algorithm to Run in Linear Time. In Revised Papers from the 10th International Symposium on Graph Drawing (GD '02). Springer-Verlag, Berlin, Heidelberg, 344–353. Fabrice Rastello. 2016. SSA-based Compiler Design (1st. ed.). Springer Publishing Company, Incorporated.