Book description
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.
Table of contents
- Build Your Own Programming Language
- Contributors
- About the author
- About the reviewers
- 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
- Technical requirements
- Understanding what bytecode is
- Comparing bytecode with intermediate code
- Building a bytecode instruction set for Jzero
- Implementing a bytecode interpreter
- Writing a runtime system for Jzero
- Running a Jzero program
- Examining iconx, the Unicon bytecode interpreter
- Summary
- Questions
-
Chapter 12: Generating Bytecode
- Technical requirements
-
Converting intermediate code to Jzero bytecode
- Adding a class for bytecode instructions
- Mapping intermediate code addresses to bytecode addresses
- Implementing the bytecode generator method
- Generating bytecode for simple expressions
- Generating code for pointer manipulation
- Generating bytecode for branches and conditional branches
- Generating code for method calls and returns
- Handling labels and other pseudo-instructions in intermediate code
- Comparing bytecode assembler with binary formats
- Linking, loading, and including the runtime system
- Unicon example – bytecode generation in icont
- Summary
- Questions
-
Chapter 13: Native Code Generation
- Technical requirements
- Deciding whether to generate native code
- Introducing the x64 instruction set
- Using registers
-
Converting intermediate code to x64 code
- Mapping intermediate code addresses to x64 locations
- Implementing the x64 code generator method
- Generating x64 code for simple expressions
- Generating code for pointer manipulation
- Generating native code for branches and conditional branches
- Generating code for method calls and returns
- Handling labels and pseudo-instructions
- Generating x64 output
- Summary
- Questions
- 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
Product information
- Title: Build Your Own Programming Language
- Author(s):
- Release date: December 2021
- Publisher(s): Packt Publishing
- ISBN: 9781800204805
You might also like
book
The Go Programming Language
is the authoritative resource for any programmer who wants to learn Go. It shows how to …
audiobook
Build a Large Language Model (From Scratch)
Learn how to create, train, and tweak large language models (LLMs) by building one from the …
book
Build a Large Language Model (From Scratch)
Learn how to create, train, and tweak large language models (LLMs) by building one from the …
book
The Rust Programming Language, 2nd Edition
The Rust Programming Language, 2nd Edition is the official guide to Rust 2021: an open source …