, 2008-10-09 (DRAFT 1)

Make Your Own Programming Language
Part 0

This is the intro to a 5-part tutorial on how to implement a programming language. It is intended for people with some programming experience, who want to know how their compiler, interpreter or virtual machine works. Hint: it's not magic.

This installment explains why you might want to make your own programming language, and why this tutorial is better than others. Feel free to skip directly to Part 1 if you're impatient.

Note: here and there I'm going to reference advanced programming topics. You can follow the links (usually to Wikipedia) at your leisure. Don't worry, it's all rather easy, actually.

Why your own programming language

There are hundreds of programming languages out there, some of which have hundreds of dialects (BASIC...), so why would anyone bother to make another one?

Reason one: It's fun!

Remember the exhilarating feeling you had when you first made a computer follow your instructions? The fun is double when you make the machine understand the instructions in the first place. Many, if not most programming languages were made for fun.

Reason two: It's useful

While you may be perfectly happy with PHP or Java most of the time, there are tasks much better expressed in other, more specialized languages. Can you imagine accessing databases whitout SQL, or processing strings whitout regular expressions? Well, many other programming tasks can benefit from domain specific languages, as they are called. If only you knew how to design and implement your own...

Reason three: For better understanding

Nobody understands a programming language better than the man who created it. For example, read what Bjarne Stroustrup has to say about teaching programming with C++. It's an eye-opening experience. But even if you never use a language of your own, making one will help you understand how the languages you do use work on the inside. You will be a better programmer ever after.

What's so special about this tutorial

There are many articles (even books!) on programming language construction. I'm writing mine with two purposes in mind:

  1. to keep it short and easy to follow by (hopefully) any programmer;
  2. to have an useful interpreter at the end of each installment.

The reader is expected to have basic-to-average programming knowledge, especially about objects, data structures and variable scope. Knowing some Javascript will help, too.

In Part 1, we'll begin to build a simple programming language. Let's call it "Scratch", since we're making it from scratch and it is designed to scratch an itch.

P.S. After completing the whole tutorial, I learned there was a Scratch programming language already, kind of an educational Smalltalk for small children. *facepalm*

Creative Commons License
Make Your Own Programming Language by Felix Pleşoianu is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.