TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Lessons learned building a toy compiler

101 pointsby k4rtikalmost 8 years ago

7 comments

throwaway2016aalmost 8 years ago
I love seeing articles like this... my compiler design course in college was one of my favorite. Also, one of the most useful. Parsers and lexers are useful in so many places besides just code compilers.<p>With that said, I think there is one small issue in the article:<p>&gt; The quintessential first step in any compiler is parsing the source string into an Abstract Syntax Tree<p>If there is a quintessential first step in writing a compiler it is doing lexical analysis with a lexer to break the program up into tokens. Then using a parser to create the AST. While you could go straight from the raw text to parsing, it makes it a lot easier if you lex it first.
评论 #14721320 未加载
评论 #14719573 未加载
评论 #14719680 未加载
loweralmost 8 years ago
It&#x27;s nice to have a small example of how to compile to LLVM, but the compiler is a bit more limited than what the blog post makes it appear.<p>It&#x27;s not quite `a compiler for simply typed lambda calculus&#x27;, but only for a small fragment without higher-order functions. One currently cannot write lambda terms that take functions as arguments.<p>I was curious how the compiler represents closures and manages memory, mainly because I&#x27;m looking for a small example of how to do garbage collection in LLVM. But it turns out that the parser doesn&#x27;t allow function types yet and the compiler itself doesn&#x27;t implement closures yet.
评论 #14721342 未加载
darioushalmost 8 years ago
I think the most underrated part is: &quot;untyped lambda calculus is harder&quot;
评论 #14721395 未加载
jaseemabidalmost 8 years ago
Author of the post here. AMA :)
评论 #14721139 未加载
louithethridalmost 8 years ago
I remember building funny little DSL-Tools with flex and bison. <a href="https:&#x2F;&#x2F;github.com&#x2F;westes&#x2F;flex" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;westes&#x2F;flex</a><p>I used it for AutoSar applications, where you create tailored embeded programs from a DSL specification.
kralljaalmost 8 years ago
Perhaps before diving into FFI, you could write a small runtime library with the basic I&#x2F;O you need (`readline` and `puts`, perhaps?)
评论 #14722922 未加载
tu7001almost 8 years ago
Great post! Interested, how it&#x27;s related to, for example, Scheme or Lisp.