Building on the work we did in the first basic tutorial, we conquered some of the harder parts of BASIC, and learned about some new power tools in Racket itself:
To make better line errors, we got clever about using exceptions to generate our errors by combining information from two places in the program.
To implement variables and input, we bit the bullet and modeled our BASIC variables as Racket variables. This made things a little harder at the outset, but paid dividends later. We saw how to use syntax properties left behind by splices in the parser to find occurrences of variables in the parse tree.
In expressions and conditionals, we learned how to implement associativity and precedence of operations with parser rules. We also considered the reasons to choose between functions and macros.
Finally, we learned about how continuations can affect control flow. In particular, how we could use them to implement subroutines and loops, which require us to jump back to previous lines in the program.
We’ll stay with BASIC just a little longer. But rather than implementing new statements, we’ll see how we can extend our implementation to cooperate with other Racket modules—whether written in BASIC, Racket, or something else. We’ll also see how to better integrate our language with the REPL and command line.