Check out "Writing An Interpreter In Go" https://interpreterbook.com/ It uses Golang to make an interpreter for a simple C-Style language and it's "only" 200 pages long. I'm about a third in and my head is smoking.
Ask HN: What's a starting point for learning how to write programming languages?
91–100 of 105 posts
Re: Ask HN: What's a starting point for learning how to write programming languages?
#92Re: Ask HN: What's a starting point for learning how to write programming languages?
#93Yes, I'm the author! There are other, more in-depth, compiler books on my homepage: http://t3x.org
The home page also contains the source code to many compilers and interpreters at different levels of complexity, from trivial to real-world.
Re: Ask HN: What's a starting point for learning how to write programming languages?
#94- kernel language, which is not a practical language, but contains all the concepts for building one of a given model
- growing said kernel language one concept at a time, when its expressiveness is stretched
- the case for multi paradigm languages, with a real example throughout the book (Oz)
- and I mean multiparadigm (although the author dislikes this word): first declarative, then with concurrency, then with ports, then with explicit state, then object oriented with and without concurrency (which in fact isn't really an extension of the kernel language), then relational ... all being simple but very careful extensions to that kernel language
- the case for each concept, which results in an extension to the language, is very carefully explained and many alternatives are considered, and much justification is given to why it would improve the language; if you are considering designing your own language, you could do worse than learning from the author's carefully described approach
- each concept results in an addition to the grammar, the semantics of which are described in detail; they are also described formally in an appendix
- whenever a new programming model is described (which is basically a set of concepts), an archetypal example is discussed: Haskell (concurrent declarative), Erlang (message passing), Java (concurrent OO), Prolog (relational)
- techniques for programming with each concept are introduced
- each chapter has exercises at the end, several of which consist of doing your own extensions to the language; some of these are research level
- as an example of how deep but accessible this book is, check the "Principal programming paradigms" poster [pdf] [2]
- the extensive bibliography at the end is fantastic
And since I believe that it hasn't been mentioned in the comments and in case you don't know yet, check out "Lambda the Ultimate", "the programming languages weblog" [3]
[1] https://www.info.ucl.ac.be/~pvr/book.html
[2] https://www.info.ucl.ac.be/~pvr/paradigmsDIAGRAMeng108.pdf
Re: Ask HN: What's a starting point for learning how to write programming languages?
#95Re: Ask HN: What's a starting point for learning how to write programming languages?
#96Re: Ask HN: What's a starting point for learning how to write programming languages?
#97Check out "Writing An Interpreter In Go" https://interpreterbook.com/ It uses Golang to make an interpreter for a simple C-Style language and it's "only" 200 pages long. I'm about a third in and my head is smoking.
That looks pretty awesome. Thanks for the suggestion. Looks like it gets to a good amount of functionality too, with first class functions and closures and the like.
For example here's a version with classes / OO-behaviour:
https://github.com/haifenghuang/monkey
Or here's my version which "just" adds some more standard-library facilities, allowing you to open/read/write files:
I found the language fun to play with, and I used a virtually identical lexer and parser-idea in a recent project of my own - rather than "parsing" an input-file with regular-expressions, which is how I would have previously approached the implementation of simple DSLs. I guess that showed I'd learned something useful!
Re: Ask HN: What's a starting point for learning how to write programming languages?
#98You can begin with writing a tiny lexer and a recursive descent parser that simply writes out the value of an expression that the user typed in. Then you can make it generate assembly for computing the expression instead (hardcoding some further assembly to print the result out at the end of the execution of the program), turning it into either a traditional compiler or a JIT compiler. Once you do that, it should not be too hard to see how to add variables and simple loops. This will already demystify things quite a bit and make further learning easier.
I specifically recommend implementing your own parser and generating assembly on your own, at least if your primary goal is learning. You could instead use an existing parser generator and e.g. a library for generating JVM bytecode, but those ready-made components are high level enough to turn it all into the usual exercise in plumbing libraries together, rather than a learning experience across many layers of the computing stack.
Re: Ask HN: What's a starting point for learning how to write programming languages?
#99Although its still in development, http://craftinginterpreters.com/ (previously on HN https://news.ycombinator.com/item?id=13406081 ) seems promising, and the existing content is good.
It helped me write the scripting language that I use in one of my projects.
Re: Ask HN: What's a starting point for learning how to write programming languages?
#100Earlier quoted context omitted.
> that is how to specify the meaning of your language and its constructs You pose the question but don't seem to answer it - this area is called semantics , and there are several approaches and notations you can use. Types and Programming Languages by Pierce is the most common starting point.
I am not posing a question. I am suggesting he look into the subject. The word "semantics" doesn't hold much meaning for many people, they understand the word "meaning" better. I could have dived straight in and suggested that he look at "denotational semantics", but I considered that just a little too much to start him off with. By the way, how much are you doing on Katadhin these day?
Some of the ideas live on in Truffle and Graal.
http://chrisseaton.com/rubytruffle/pldi17-truffle/pldi17-tru...