-
Book Overview & Buying
-
Table Of Contents
Building Programming Language Interpreters
By :
Some use cases benefit from an entirely separate language focused on that particular problem. We call those domain-specific languages (DSLs). They solve specific types of problems that don’t fit well with the existing programming languages. They eliminate the need to express things that are not part of the problem and allow us to focus on the problem itself.
A great example of a language that is used a lot, but that most people wouldn’t consider using in situations other than the one it’s already used, is SQL. It is a language that focuses on expressing complicated relational algebra in a way that is intuitive and where you don’t have to specify unrelated operations to the problem you’re solving, meaning that there is less opportunity for bugs in the code.
A tool that is extremely powerful and that has become an integral feature of most programming languages is regular expressions. Specifying how to match a string against complex rules would be massively error prone if the developer didn’t have access to that specific language.
The two examples provided happen to be languages that often belong to entirely different paradigms than the one the developer is using to write the broader application code, and this is not a coincidence. The declarative nature of regular expressions makes them very different from the imperative nature of the language usually surrounding their use. And it’s that ability to easily go from being imperative to declarative that is the greatest power of DSLs. In Chapter 6, Review of Programming Language Paradigms, I will discuss the various programming language paradigms.
Before jumping into the programming language that we’ll be designing in this book, it is important to take a step back and think about how our code will run.