Ask HN: Best books on building a programming language
14 points
12 hours ago
| 6 comments
| HN
I have this long thought about building a language for the age of ai.

Here is a non-exhaustive list of features i would love to have it included: - separate effect full code from pure logic - separate state and code - ai native debugger - native deterministic simulation testing - coding proofs - explicit type system - repl - wasm target

I have no background in compiler building or similar. I would just like to spend some weeks reading the best resource about this topic.

Please share any resource you recommend reading.

zerr
31 minutes ago
[-]
When it comes to PL implementations, there are lesser materials about creating relevant tools besides compilers: linkers and especially debuggers. Are there any coursers/books that go into implementing these tools?
reply
vladimir-vg
1 hour ago
[-]
What I can assure you about, is that you DO NOT NEED to learn how to create runtimes, compilers or translators.

The challenge isn't really in building a decent implementation or adopting useful features. There are plenty of languages with decent implementations and features that are on display in Github graveyard.

The challenge is to deeply understand what THE PROBLEM is. Books won't help you with that at all. Long walks, drinking fresh water, meditation, prayer. It may take years.

And once you understood the problem, the path is clear: research and studying prototypes of other people helps greatly.

What is the problem that you're trying to solve? You listed the features, not the issue you're aiming at.

reply
markus_zhang
8 hours ago
[-]
Crafting interpreters. Very well written and free of cost, but ofc I’d recommend purchasing a copy.

If you find it a bit hard to chew, there is a simpler book using Python: https://www.amazon.ca/Anthony-J-Dos-Reis/e/B001KE4SU8/ref=dp...

Another book: Game Scripting Mastery.

reply
stevekemp
5 hours ago
[-]
Crafting Interpreters is a good recommendation, and in the same spirit "Writing an Interpreter in Go" (and it's followup about writing a virtual machine) is a good addition.

A lot of the complexity and front-work of these kinda things is the parsing step though, so you can follow MAL (or any other make a lisp tutorial) though that won't necessarily help with other languages it frees you to jump to the interesting parts.

FORTH, mentioned in another comment, has that same appeal. I wrote a quick tutorial here, back in the day:

https://github.com/skx/foth

reply
gabrielsroka
2 hours ago
[-]
Related? An AI lang from the creator of Kotlin

https://codespeak.dev

reply
tnelsond4
12 hours ago
[-]
I tried reading the dragon book in my teens, never really understood it, it was too much theory for me.

I'd recommend starting with implementing a forth since it's the easiest language to write an interpreter/compiler for. From there you'll have enough experience to go for something bigger.

Making your own bytecode is really fun.

Ultimately you'll probably want your compiler to target llvm bytecode so that it works on every target automatically.

reply
skydhash
3 hours ago
[-]
> separate effect full code from pure logic

That’s a feature of the abstract machine. TM and Von Neuman is very reliant on a global (and locals) state. Lambda calculus does not and instead requires evaluation (or reduction in symbolic terms).

Best bet for this is some book on computation theory, but as the name says, they’re full of theory, but it’s kinda the foundation of everything.

> separate state and code

Not really possible. The name “code” cames from the fact that you’re encoding logic and data to represent a process. It’s a closed system and the above books explain how and why it works.

> ai native debugger

What does that mean? A debugger is mostly the capability to stop a process and inspect the current state. How does AI helps?

> native deterministic simulation testing

What does that means?

> coding proofs

Again, the books on computation theory will helps. Most of them will only explain the context free grammars (tightly coupled to TM). There’s a bunch of abstraction on top of that that leads to C, JavaScript and Python. There’s also the various other systems like Horn clauses, lambda calculus, and relational algebra. All have mathematical models that are the basics of such proofs.

> explicit type system

The main book I can recommend is Types and Programming Languages by Pierce. It also requires a good knowledge of basic computation theory. Quick note: Computation does data transformation, types helps with proving that.

> repl

While not impossible, it clashes with the above. Explicit typing is cumbersome to write while REPL is all about quick iteration. Some simple software like ed and ksh can help there.

> wasm target

Going from assembly to C is about design abstractions, compiling C to assembly is building those abstractions. Targeting wasm is about design what would take you to go from wasm to you abstract machine that is capable of executing your language and then starting to build it.

reply