ENGLISH

Writing An Interpreter In Go

Book information

Publisher
Thorsten Ball
Year
2017
ISBN
300055808X, 9783000558085
Language
english
Format
PDF
Filesize
1010 kB (1034604 bytes)
Edition
1
Pages
262\206
Time added
2022-07-11 16:18:06

Description

In this book we will create a programming language together. We'll start with 0 lines of code and end up with a fully working interpreter for the Monkey programming language. Step by step. From tokens to output. All code shown and included. Fully tested. Buy this book to learn: - How to build an interpreter for a C-like programming language from scratch - What a lexer, a parser and an Abstract Syntax Tree (AST) are and how to build your own - What closures are and how and why they work - What the Pratt parsing technique and a recursive descent parser is - What others talk about when they talk about built-in data structures - What REPL stands for and how to build one Why this book? This is the book I wanted to have a year ago. This is the book I couldn't find. I wrote this book for you and me. So why should you buy it? What's different about it, compared to other interpreter or compiler literature? - Working code is the focus. Code is not just found in the appendix. Code is the main focus of this book. - It's small! It has around 200 pages of which a great deal are readable, syntax-highlighted, working code. - The code presented in the book is easy to understand, easy to extend, easy to maintain. - No 3rd party libraries! You're not left wondering: "But how does tool X do that?" We won't use a tool X. We only use the Go standard library and write everything ourselves. - Tests! The interpreter we build in the book is fully tested! Sometimes in TDD style, sometimes with the tests written after. You can easily run the tests to experiment with the interpreter and make changes. This book is for you if you... - learn by building, love to look under the hood - love programming and to program for the sake of learning and joy! - are interested in how your favorite, interpreted programming language works - never took a compiler course in college - want to get started with interpreters or compilers… - ... but don't want to work through a theory-heavy, 800 pages, 4 pounds compiler book as a beginner - kept screaming "show me the code!" when reading about interpreters and compilers - always wanted to say: "Holy shit, I built a programming language!" Acknowledgments Introduction The Monkey Programming Language & Interpreter Why Go? How to Use this Book Lexing 1.1 - Lexical Analysis 1.2 - Defining Our Tokens 1.3 - The Lexer 1.4 - Extending our Token Set and Lexer 1.5 - Start of a REPL Parsing 2.1 - Parsers 2.2 - Why not a parser generator? 2.3 - Writing a Parser for the Monkey Programming Language 2.4 - Parser's first steps: parsing let statements 2.5 - Parsing Return Statements 2.6 - Parsing Expressions Expressions in Monkey Top Down Operator Precedence (or: Pratt Parsing) Terminology Preparing the AST Implementing the Pratt Parser Identifiers Integer Literals Prefix Operators Infix Operators 2.7 - How Pratt Parsing Works 2.8 - Extending the Parser Boolean Literals Grouped Expressions If Expressions Function Literals Call Expressions Removing TODOs 2.9 - Read-Parse-Print-Loop Evaluation 3.1 - Giving Meaning to Symbols 3.2 - Strategies of Evaluation 3.3 - A Tree-Walking Interpreter 3.4 - Representing Objects Foundation of our Object System Integers Booleans Null 3.5 - Evaluating Expressions Integer Literals Completing the REPL Boolean Literals Null Prefix Expressions Infix Expressions 3.6 - Conditionals 3.7 - Return Statements 3.8 - Abort! Abort! There's been a mistake!, or: Error Handling 3.9 - Bindings & The Environment 3.10 - Functions & Function Calls 3.11 - Who's taking the trash out? Extending the Interpreter 4.1 - Data Types & Functions 4.2 - Strings Supporting Strings in our Lexer Parsing Strings Evaluating Strings String Concatenation 4.3 - Built-in Functions len 4.4 - Array Supporting Arrays in our Lexer Parsing Array Literals Parsing Index Operator Expressions Evaluating Array Literals Evaluating Index Operator Expressions Adding Built-in Functions for Arrays Test-Driving Arrays 4.5 - Hashes Lexing Hash Literals Parsing Hash Literals Hashing Objects Evaluating Hash Literals Evaluating Index Expressions With Hashes 4.6 - The Grand Finale Resources Feedback Changelog

Similar books