How to create pragmatic, lightweight languages
This book is 100% complete
Completed on 2018-03-06
About the Book
This book shows how we can reuse existing libraries and frameworks to create all the ecosystem necessary to support our languages.
The cost of building all the machinery to proper support a language used to be very high. Today with a limited effort we can design a language and obtain:
- a fast parser from a concise grammar definition
- validation and model transformations with very few code
- generate JVM bytecode and get interoperability with other JVM languages
- obtain rich editors with syntax highlighting and autocompletion
We will see how to build all of this and more by defining small components in a smart way. The result will be something solid, complete and understandable.
1. Motivation: why do you want to build language tools?
- Why to create a new language?
- Why to invest in tools for languages?
2. The general plan
- How the different tools are related
- Technology used for the examples
3. The example languages we are going to build
- Part I: the basics
4. Writing a lexer
- Why using ANTLR?
- The plan
- The Lexer grammar for MiniCalc
- The Lexer grammar for StaMac
5. Writing a parser
- The parser grammar for MiniCalc
- The parser grammar for StaMac
6. Mapping: from the parse-tree to the Abstract Syntax Tree
- General support for the Abstract Syntax Tree
- Defining the metamodel of the Abstract Syntax Tree
- Mapping the parse tree into the Abstract Syntax Tree
- Testing the mapping
7. Symbol resolution
- Example: reference to a value in Java
- Example: reference to a type in Java
- Example: reference to a method in Java
- Resolving symbols in MiniCalc
- Resolving symbols in StaMac
- Testing the symbol resolution
- Typesystem rules
- Let’s see the code
- Typesystem for MiniCalc
- Typesystem for StaMac
- Validation for MiniCalc
- Validation for StaMac
- Part II: compiling
10. Build an interpreter
- What you need to build an interpreter
- Let’s see the code
11. Generate JVM bytecode
- The Java Virtual Machine
- The main instructions
12. Generate an executable using the LLVM
- What is the LLVM?
- Installing LLVM
- Working with LLVM IR
- Part III: editing support
13. Syntax highlighting
- How to write an ANTLR lexer for syntax highlighting
- Supporting multiple languages
- Different forms of autocomplete
- How to calculate syntatic options
- How to calculate semantic options
- Write to me
The Book and the Code
The book in PDF, epub, mobi (Kindle) + all the code organized in modules, with build files and tests
The code, with build files and tests
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...