
- 494 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Build Your Own Programming Language
About this book
Written by the creator of the Unicon programming language, this book will show you how to implement programming languages to reduce the time and cost of creating applications for new or specialized areas of computing
Key Features
- Reduce development time and solve pain points in your application domain by building a custom programming language
- Learn how to create parsers, code generators, file readers, analyzers, and interpreters
- Create an alternative to frameworks and libraries to solve domain-specific problems
Book Description
The need for different types of computer languages is growing rapidly and developers prefer creating domain-specific languages for solving specific application domain problems. Building your own programming language has its advantages. It can be your antidote to the ever-increasing size and complexity of software.In this book, you'll start with implementing the frontend of a compiler for your language, including a lexical analyzer and parser. The book covers a series of traversals of syntax trees, culminating with code generation for a bytecode virtual machine. Moving ahead, you'll learn how domain-specific language features are often best represented by operators and functions that are built into the language, rather than library functions. We'll conclude with how to implement garbage collection, including reference counting and mark-and-sweep garbage collection. Throughout the book, Dr. Jeffery weaves in his experience of building the Unicon programming language to give better context to the concepts where relevant examples are provided in both Unicon and Java so that you can follow the code of your choice of either a very high-level language with advanced features, or a mainstream language.By the end of this book, you'll be able to build and deploy your own domain-specific languages, capable of compiling and running programs.
What you will learn
- Perform requirements analysis for the new language and design language syntax and semantics
- Write lexical and context-free grammar rules for common expressions and control structures
- Develop a scanner that reads source code and generate a parser that checks syntax
- Build key data structures in a compiler and use your compiler to build a syntax-coloring code editor
- Implement a bytecode interpreter and run bytecode generated by your compiler
- Write tree traversals that insert information into the syntax tree
- Implement garbage collection in your language
Who this book is for
This book is for software developers interested in the idea of inventing their own language or developing a domain-specific language. Computer science students taking compiler construction courses will also find this book highly useful as a practical guide to language implementation to supplement more theoretical textbooks. Intermediate-level knowledge and experience working with a high-level language such as Java or the C++ language are expected to help you get the most out of this book.
]]>
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Information
Section 1: Programming Language Frontends
- Chapter 1, Why Build Another Programming Language?
- Chapter 2, Programming Language Design
- Chapter 3, Scanning Source Code
- Chapter 4, Parsing
- Chapter 5, Syntax Trees
Chapter 1: Why Build Another Programming Language?
- Motivations for writing your own programming language
- The difference between programming languages and libraries
- The applicability of programming language tools to other software projects
- Establishing the requirements for your language
- A case study that discusses the requirements for the Unicon language
So, you want to write your own programming language…
Types of programming language implementations
- A pure interpreter that executes source code itself
- A native compiler and a runtime system, such as in C
- A transpiler that translates your language into some other high-level language
- A bytecode compiler with an accompanying bytecode machine, such as Java
Organizing a bytecode language implementation
- A lexical analyzer reads in source code characters and figures out how they are grouped into a sequence of words or tokens.
- A syntax analyzer reads in a sequence of tokens and determines whether that sequence is legal according to the grammar of the language. If the tokens are in a legal order, it produces a syntax tree.
- A semantic analyzer checks to ensure that all the names being used are legal for the operations in which they are being used. It checks their types to determine exactly what operations are being performed. All this checking makes the syntax tree heavy, laden with the extra information about where variables are declared and what their types are.
- An intermediate code generator figures out memory locations for all the variables and all the places where a program may abruptly change execution flow, such as loops and function calls. It adds them to the syntax tree and then walks this even fatter tree before building a list of machine-independent intermediate code instructions.
- A final code generator turns the list of intermediate code instructions into the actual bytecode in a file format that will be efficient to load and execute.

Languages used in the examples
Table of contents
- Build Your Own Programming Language
- Contributors
- Preface
- Section 1: Programming Language Frontends
- Chapter 1: Why Build Another Programming Language?
- Chapter 2: Programming Language Design
- Chapter 3: Scanning Source Code
- Chapter 4: Parsing
- Chapter 5: Syntax Trees
- Section 2: Syntax Tree Traversals
- Chapter 6: Symbol Tables
- Chapter 7: Checking Base Types
- Chapter 8: Checking Types on Arrays, Method Calls, and Structure Accesses
- Chapter 9: Intermediate Code Generation
- Chapter 10: Syntax Coloring in an IDE
- Section 3: Code Generation and Runtime Systems
- Chapter 11: Bytecode Interpreters
- Chapter 12: Generating Bytecode
- Chapter 13: Native Code Generation
- Chapter 14: Implementing Operators and Built-In Functions
- Chapter 15: Domain Control Structures
- Chapter 16: Garbage Collection
- Chapter 17: Final Thoughts
- Section 4: Appendix
- Appendix: Unicon Essentials
- Assessments
- Other Books You May Enjoy