Attila's Blog

About writing your own programming language in C, Go and Swift

Why should I do this?

May 25, 2018 Comments

Categories: aspl

Why, really?

Before we start, let’s try to answer the question: What possible benefit could I gain by doing this?

Pretty much every big project could benefit from something called “domain specific languages (DSL)”. These are small languages specialized to specific application domains.

You could say: ” – Ok, it’s nice but I don’ use anything like that”.

Well, I have to disagree. Have you ever used any of these?

  • HTML
  • SQL
  • XML
  • XSLT
  • CSS
  • Bash scripts
  • JSON
  • INI files
  • YAML

If the answer is yes —surprise!— you use them a lot. Because these are all DSLs.

You probably agree that literally every project will use at least some of these.

Now your next thought is: ” – Ok, you got me. I use DSLs. So what?”

If you understand how they are built you will have a serious edge over your competition. Why? In reality, there is always a task for which there is no existing library yet. Or worse, there is a twenty–something years old, that is crappy, full of bugs and not maintained anymore and you wouldn’t touch it with a ten–foot pole. It is inevitable that there will be a time when you have to write a library for a very specific domain in your project, ergo you have to write a DSL. This is where this new knowledge will come in handy, you will be able to create something —not only shiny but useful as well— that fits the bill perfectly. This is what.

By writing a programming language of your own you will learn how to design and write DSLs. Trust me, it is going to be an invaluable tool in your arsenal.

With that said, writing a language is also a great exercise, and a serious test of your skills. It will make you learn about algorithms and data structures, an area only a few people really understands, although we all use them every day. Are you a Java developer? I am sure you use the collections framework day in and out. But do you know what it does behind the scenes? How it is built? How the different implementations perform? Do you know which implementation to choose for a specific task?

If not sure, one more reason to follow this series and write the presented code for yourself.

You will learn dynamic arrays, recursive algorithms, binary trees, hash tables and some. You will also implement these on your own, so I can guarantee that by the time we finish our work together, you will know exactly how they work.

The main reason I’ve chosen C as the language for this project is that C is very low level and gives you almost nothing to work with. None of the previously mentioned data structures are implemented in the standard library. If you need them, you have to create them for yourself (at least I chose to do it this way for learning purposes).

My promise is that by the time you finish, you will fully understand how your favourite language itself was made. Are you a Java developer? Or Swift / C# / Python / Ruby / PHP / JavaScript? Wouldn’t it be great to know what makes them tick?

I can help you with that if you choose to follow me.

How do we start?

Before writing any code you need to learn some theory used by programming languages, and the connection between the different parts.

This is where we will start next time.

Stay tuned. I’ll be back.

Tags: DSL Domain Specific Languages

← Introduction Building Blocks of a Programming Language →

comments powered by Disqus