Our journey is made of 4 stations - each of them depending on the previous ones:
LISP
syntax - into an array of tokens.C
-like code.(The interactive code snippets are powered by a tool of mine named KLIPSE.)
The last station: the compilerThe last station is only fun - lot of fun!!!
Let’s write our last piece of code - by assembling the tokenizer
, the parser
and the emitter
into a single my_compiler
function:
1+2
my_compiler = input => {
let tokens = tokenizer(input);
let ast = parser(tokens);
let output = emitter(ast);
return output;
}
And let’s test it…
my_compiler("(add 1 2 (mult 3 4))")
Enjoy the moment, play with your compiler…
Congratulations - I mean you did it. Give yourself a huge hug, buy yourself a gift. I don’t know… Find the most appropriate way to celebrate your success… You truly deserve it!
One last thing: the whole code is accessible as a single file on github: it’s around 150 line of codes.
Subscribe to Yehonathan Sharvit newsletterGet the latest and greatest from Yehonathan Sharvit delivered straight to your inbox every week.
Read Next TagsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4