A step-by-step coding essay

Here, I am starting publishing the chapters of my book, Creating a Compiler with Raku. I am planning to add a new chapter every week on Sundays.

Contents

Chapter 1. Creating a Simple Interpreter

Grammar

Actions

Modules

Chapter 2. Parsing a Number

Finding a number

Getting the value

Using AST

Final notes

Chapter 3. Creating a Calculator

Enrolling a sum

Premature optimization

More operands

A diversity test

Adding more math

Testing the code

Adding more power

Allowing parentheses

Chapter 4. A Better Interpreter

Skipping comments

Sophisticated numbers

Sophisticated expressions

Using variables

Declaration with initialization

Chapter 5. Working on Grammar

Executable

Composing and inheriting grammars

Reviewing the calculator

Using multi-rules

Get rid of globals

Better variable names

Functions take expressions

Chapter 6. Working with Strings

Strings

Escaping quotes

Indexing a string

Chapter 7. Arrays and Hashes

Arrays

Assigning to an array item

Side story: The joy of syntax

Accessing array elements

List assignments

Printing arrays

Hashes

Review and test

Chapter 8. Building AST. Part 1

Thinking of the if keyword

keyword The AST blocks

Value nodes

Chapter 8. Building AST. Part 2

Declaring strings

Declaring arrays and hashes

Scalar assignment

Working with indices

Array and hash assignment and initialisation

AST for expressions

Function calls

Final tuning

Chapter 9. Evaluating AST

Evaluating from the top

Working with variables

String interpolation

Using Raku getters

Interpolating everywhere

Arithmetic operations

Chapter 10. Test Suite

Test runner

Tests Numbers Strings Expressions Arrays and hashes

Spotting the errors

Feature coverage

It is never enough

Chapter 11. Control Flow

Implementing if

Implementing else

Implementing a loop

Statement blocks

Blocks in the AST

A real-life test

Conditional operators

Implementing the while loop

Chapter 12. Functions

The book was started when Raku was Perl 6, so it may occasionally happen that you see the old name of the language (would I start it today, I might misspell it too :-).

Return to this page later to see the next chapter.

You are welcome to leave comments, both as comments under the chapters, as well as via email.