Our cut-down version of BASIC won’t be able to handle a program like Eliza. But it shows how we can apply the same techniques we learned in the silly bf and the simple jsonic to build a more sophisticated language:
Even though BASIC has a very different control flow than Racket—including the famous goto—we figured out how these elements either corresponded to existing elements in Racket (e.g., lines becoming functions) and how others could be implemented in Racket (e.g., a program loop using for/fold).
We saw how to automatically collect source locations in the lexer, so we get more precise error messages, and graphical error highlighting in DrRacket. We also separated out our lexer from the tokenizer—later, we can reuse it as the basis of a syntax colorer.
We learned about how to make cuts and splices in the parser to streamline the parse tree by filtering out unnecessary elements.
In the expander, we learned some new macro tricks, including fancier matching with syntax patterns, and generating new identifiers with prefix-id.
We also learned how to use exceptions to send signals within our language, allowing us to rewire the control flow.