3 ms·
Nice, but it needs to say up front what it does (i.e., compile a Lisp-ish PL to a C-ish PL). EDIT. After a bit of analysis: The lexer is basically a state mac
by ggchappell 11y ago
Nice, but it needs to say up front what it does (i.e., compile a Lisp-ish PL to a C-ish PL).
EDIT. After a bit of analysis:
The lexer is basically a state machine. Each kind of token consists entirely of characters in a single class, so the usual state machine is modified to give some states a while loop that goes through characters until the token ends.
The parser is basically recursive-descent. The grammar is awfully simple, so only one parsing function (walk) is needed.
The transformer traverses the AST, identifies function calls, and produces a new AST with function calls marked. I'm not sure why the transformer is written as a separate piece of code. It seems to me that the functionality it adds could easily be integrated into either the parser or the code generator. And then the compiler would be even tinier.
And the code generator traverses the transformed AST and spits out C-like code.