Sunday 13 March 2016

Implementing a programming language in C - Introduction

Why?


There is a point in every programmers life where they are confronted with a problem which they think is unnecessarily tedious to solve in language X. You think "Hmm, if only language X had feature Y, it would make my life so much easier." Thus begins your journey into the endless abyss that is programming language design and implementation.

Your first instinct is to research. You scour whatever resources you have at your disposal to learn as much about the subject as possible. "What's this?" you ask yourself. "A book that discusses this very subject? Marvelous! It's even referred to as the 'dragon book'! It must be a fun read!"

Things are looking up. You might just be on your way to being the next Dennis Ritchie. You torrent a PDF version of the book, and open the document. You work your way through the dense introduction, a couple chapters maybe, but find yourself none the wiser for it. Dismayed, you restore your minimized text editor, and continue programming in language X.

But maybe, you were very persistent when looking for resources. Perhaps you checked the third or even the fourth page of google and encountered this blog.

You came to the right place.

Despite what most programmers think, implementing a programming language isn't a gargantuan task fit only for the Computer Science PhDs of the world. In fact, you can make one right now if you follow this tutorial.

 

The language


The language we'll be implementing has the following syntax. Do note that this is by far the least important aspect of the language, but one which most people who try this sort of thing dwell on the most (I mean, syntax has some importance insofar as how difficult it is to parse).

Here is what the language we'll be making will look like:

With all the imagination I could muster, I decided to name the language 'Tut'.

As you can see, it is a pretty complex language as far as tutorial languages go. Anyways, this will be the language we'll be implementing over the course of the next few tutorials.

Thanks for reading.

1 comment:

  1. Good start. I myself never got past the dense introduction of the dragon book :)

    ReplyDelete