5 ms·
A dynamic tutorial about a compiler in one JavaScript file (2016)
- klohto 5y agoYou can just link the original file https://github.com/jamiebuilds/the-super-tiny-compiler/blob/master/the-super-tiny-compiler.js https://github.com/jamiebuilds/the-super-tiny-compiler/blob/...
- dang 5y agoChanged from https://gist.github.com/roramigator/3806a55947b11bf9e27c42331614460b https://gist.github.com/roramigator/3806a55947b11bf9e27c4233.... Thanks!
- deleted 5y ago[deleted]
- taftster 5y agoAnd it's super readable too. Very concise but descriptive. The author has a friendly tone and the code is easy to follow, even if you're not familiar with javascript syntax. Good fun!
- dang 5y agoPast related threads: An ultra-simplified example of a modern compiler written in JavaScript - https://news.ycombinator.com/item?id=22522208 https://news.ycombinator.com/item?id=22522208 - March 2020 (27 comments) Super Tiny Compiler - https://news.ycombinator.com/item?id=11395656 https://news.ycombinator.com/item?id=11395656 - March 2016 (100 comments)
- tomcam 5y agoIt would be my instinct to hoist the walk() function out of the parse() function but that's because my compiler writing experience is limited to C and Pascal. What is the thinking behind this decision? Not criticism, just trying to learn Javascript better
- colejohnson66 5y agoLocal functions like that make sense if you want to access the outer function’s state - which is what’s happening here with `current`. It also makes it so others can’t use that function without having to make a separate module. Almost like a scoped “global” state. See also: IIFEs: https://developer.mozilla.org/en-US/docs/Glossary/IIFE https://developer.mozilla.org/en-US/docs/Glossary/IIFE
- tomcam 5y agoOf course! Totally obvious… Now that you bring it up! That’s much nicer than my non-scoped instinct. Thank you.