Compiling a Lisp: Reader
bernsteinbear.com
Compiling a Lisp: Reader
1–10 of 30 posts
Re: Compiling a Lisp: Reader
#2It compiles to Javacript and Lua, so if you prefer reading those, you can:
https://github.com/sctb/lumen/blob/master/bin/reader.js
https://github.com/sctb/lumen/blob/master/bin/reader.lua
It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so, try converting it to a number."
That turns out to handle cases like 1e9 too. Whereas "1e" becomes a valid lisp symbol. So you can set it to your own value.
The emacs source code is also worth reading. It's not simple, but it's simple enough to be understandable: https://github.com/emacs-mirror/emacs/blob/7b3e94b6648ed00c6...
I like emacs source code because it handles "every possible real-world case that you can think of."
Re: Compiling a Lisp: Reader
#3For a very simple, very readable Lisp reader, see Lumen's reader.l file: https://github.com/sctb/lumen/blob/master/reader.l It compiles to Javacript and Lua, so if you prefer reading those, you can: https://github.com/sctb/lumen/blob/master/bin/reader.js https://github.com/sctb/lumen/blob/master/bin/reader.lua It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so…
Re: Compiling a Lisp: Reader
#4I'm the author and here to answer questions and take constructive criticism.
If you want to comment but don't have an HN account, please check out the mailing list: https://lists.sr.ht/~max/compiling-lisp
Re: Compiling a Lisp: Reader
#5For a very simple, very readable Lisp reader, see Lumen's reader.l file: https://github.com/sctb/lumen/blob/master/reader.l It compiles to Javacript and Lua, so if you prefer reading those, you can: https://github.com/sctb/lumen/blob/master/bin/reader.js https://github.com/sctb/lumen/blob/master/bin/reader.lua It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so…
Re: Compiling a Lisp: Reader
#6For a very simple, very readable Lisp reader, see Lumen's reader.l file: https://github.com/sctb/lumen/blob/master/reader.l It compiles to Javacript and Lua, so if you prefer reading those, you can: https://github.com/sctb/lumen/blob/master/bin/reader.js https://github.com/sctb/lumen/blob/master/bin/reader.lua It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so…
Why are atoms that start with numbers accepted as symbols? Is there any usecase for that?
Re: Compiling a Lisp: Reader
#7Oh cool, someone else besides me posted my blog :D I'm the author and here to answer questions and take constructive criticism. If you want to comment but don't have an HN account, please check out the mailing list: https://lists.sr.ht/~max/compiling-lisp
From another lisper, congrats and well done!
Re: Compiling a Lisp: Reader
#8Racket (if you're not aware of what it is) is just a lisp, but the standard library includes an incredible amount of support for creating readers and expanders for programming languages with very little effort.
You aren't even limited to Racket as the target language for your compilation. It's incredibly easy to formulate whatever output you want (like assembly in this article).
Of course there's still an incredible amount of value and fun in doing everything from scratch like this article's series describes. One of the most intellectually rewarding things I've ever done is working through nand2tetris.
You have a great blog /u/tekknolagi.
Re: Compiling a Lisp: Reader
#9I've been working my way through Beautiful Racket [1] over the last week or so. It's been awesome. If this kind of thing is of interest to you, I highly recommend it. It's a book focused on a way of thinking that involves building small domain-specific languages to solve your problems. It's so easy. Racket (if you're not aware of what it is) is just a lisp, but the standard library includes an incredible amount of su…
Re: Compiling a Lisp: Reader
#10Oh cool, someone else besides me posted my blog :D I'm the author and here to answer questions and take constructive criticism. If you want to comment but don't have an HN account, please check out the mailing list: https://lists.sr.ht/~max/compiling-lisp
I love seeing long form blog posts like this! Whilst its not something I’d personally do for a long time, its great to have resources on the web that go into detail in advanced topics like building a lisp interpreter. From another lisper, congrats and well done!