Chapter 7. Arrays and Hashes

This is a chapter fromCreating a compiler with Raku In this chapter, we will extend the Lingua language with aggregate data types: arrays and hashes. From this point, we will call variables that contain numbers and strings scalar variables. Arrays Arrays are collections of elements which share their common variable name and are accessible via integer indices. … Continue reading “Chapter 7. Arrays and Hashes”

Chapter 6. Working with Strings

This is a chapter fromCreating a compiler with Raku Until now, the language only worked with numbers—integer and floating point, both in regular and in scientific notation. In the following two chapters, we’ll update the language and integrate other data types to it: strings, arrays, and hashes. Let us start with strings. Strings The first … Continue reading “Chapter 6. Working with Strings”

Chapter 5. Working on Grammar

This is a chapter fromCreating a compiler with Raku In this chapter, we’ll review the grammar that was created so far and will try to make some changes to make the grammar and the actions more compact, more readable and more user-friendly. The bigger the language becomes, the more important it is to keep its … Continue reading “Chapter 5. Working on Grammar”

Chapter 4. A Better Interpreter

This is a chapter fromCreating a compiler with Raku This chapter is dedicated to Jeff Goff, who was one of the most active promoters of Raku grammars The goal of this chapter is to build a better interpreter using all the achievements of the previous three chapters. The new interpreter will be able to work … Continue reading “Chapter 4. A Better Interpreter”

Chapter 3. Creating a Calculator

This is a chapter fromCreating a compiler with Raku In this chapter, we will create a program that can evaluate simple arithmetic expressions such as 3 + 4  or 3 – 3 * 7. We’ll start from the simplest equations with two operands and will work until we can introduce parentheses. Enrolling a sum Let us first … Continue reading “Chapter 3. Creating a Calculator”

Chapter 2. Parsing a Number

This is a chapter fromCreating a compiler with Raku In the following two chapters, we will temporary leave the compiler created in the previous chapter, and will be working on a separate helper project, a calculator. It is an interesting thing on its own, and we will explore it on an isolated example. In the … Continue reading “Chapter 2. Parsing a Number”

Chapter 1. Creating a Simple Interpreter

This is a chapter fromCreating a compiler with Raku Let’s start exploring the power or Raku’s grammars and regexes from a simple interpreter program that parses and executes the following tiny program. I will call this language Lingua. my x;x = 42;say x; You should not experience any problems with understanding what this code means, as … Continue reading “Chapter 1. Creating a Simple Interpreter”