From some time I have been working on a book about creating languages.
Why?
Because I think that languages are extremely useful tools and by creating languages and supporting tools we have the power to completely change how people and organizations work. I have seen the effect languages can have on productivity in real companies, and I think that more organizations should get those benefits.
Creating a language has been regarded as a very difficult challenge. I think this doesn’t need to be the case: with the right approach, we can build languages with a reasonable effort.
There are two very different ways to build languages: one way is to use Language Workbenches like Jetbrains MPS or Xtext. In some cases this is the right choice: there are limitations attached to that choice but also advantages in terms of rapidity of development. The second way is to do without Language Workbenches. For this second way there is no clear path, it’s a path which requires a lot of learning, and trial and error. However it has the benefit of putting us in control: being able to shape an environment for our language exactly as we need it. The possibility of designing a simple architecture which we can completely understand, control, change. This idea is inspired by the unix philosophy of having small, simple components and combining them to obtain a complex result. I describe this path in this book.
Table of contents
1. Motivation: why do you want to build language machinery?
2. The general plan
Part I: the basics
3. Writing a lexer
4. Writing a parser
5. Mapping: from the parse-tree to the Abstract Syntax Tree
6. Symbol resolution
7. Typesystem
8. Validatdation
Part II: compiling
9. Writing an interprter
10. Generate JVM bytecode
11. Generate LLVM bytecode
Part III: editing support
12. Syntax highlighting
13. Auto completion
These are the chapters I will write for sure, with the first five chapters already written. Depending on the support I receive, I plan to add more chapters or leave the table of contents as it is. I could also provide the examples in more languages (Python or C#, for example).
How you can help me
You can get the book from LeanPub. It would be a great help if you could give me feedback on the table of contents, on what you would like to be added, on the chapters already written, or on the examples provided. This will help me improve the book.
Update
The book is now finished, polished and is periodically updated. It also has a shining new and professional cover, so, it doesn’t lack anything. You can find more about it on How to Create Pragmatic, Lightweight Languages.
Conclusions
For me, writing this book was useful to crystallize my experience and think about how to efficiently build languages. I think that building the right languages has a very strong impact on software development. I try to help with that in this book.
Originally written in December 2016, updated on February 2017