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”

Implementing a stack-based language in Raku

I assume there is no need to tell what a stack is, and a stack-based programming is something that uses the stack to perform all the operation. The program flow in such a language resembles a reversed Polish notation, when you first list the operands, and then the operation: 40 2 + There are a … Continue reading “Implementing a stack-based language in Raku”