Every Programmer Should Build Their Own Programming Language

Every Programmer Should Build Their Own Programming Language

·

4 min read

Why

Every Programmer should design their own programming language. Not only does this expand your programming skills, but it is also a great way to learn how computers and computer languages work. I learned so much about programming in general as I made my language EZCode.

A programming language is like a way of thinking. It's somebody's view on how you should interact with a computer. Every language is different and has its own ups and downs. You also have your own personal preferences. Let's say you love writing in Python, but also like the bracket syntax of JavaScript or C based languages. Maybe you like the Linq queries in C# but not its wordy syntax. These are all different opinions that you might have. Just to know what you do and don't like is a good thing in general. Sure, you may not be able to build a language that could actually be useful enough to use, but this isn't the point.

Type of Languages

What you learn as you build your language depends on what you do. There are generally two main types of languages,

  • Compiler: Converts a high-level language into machine code in an executable application.

  • Interpreter: An application that goes through your code and executes each line in order.

I decided to make my language as an interpreter because it was easier to create when I was still learning the concepts.

Interpreter

An interpreter is generally easier to make, but has a lot more drawbacks in the finished language. The plus side of making an interpreter is the ease to make your syntax however you would like. The downside is that it can be slower by a lot. If you design the language in something like Python, the performance isn't going to be great.

Compiler

A compiler is generally harder and more complicated to make. This is because the language needs to be converted into assembly. I would not suggest making a compiler unless you have at least a small concept of how assembly works. You will also have to use tools like gnu for assembling and linking.

Transpiling

Another option is Transpiling. Transpiling is like a compiler, but instead of converting to assembly, you convert to another programming language. It is basically translating your language into another popular language. C++ is a transpiler because it translates itself into C.

High or Low Level Language

Generally, most popular languages are high-level because they are more easily read. To make a low-level language, you might need a deeper understanding of how a computer works. Assembly is an example of a low-level language. Languages like C, Python, or any other popular language are examples of high-level programming languages.

How to Build It

First, pick the language to write it in. Feel free to choose any language that you are comfortable in. If it's Python, use Python even though it might be slower. I used C# for my language because I'm comfortable writing in it. After that, decide how you're going to build it. There are many good tutorials out there, but I would suggest giving a crack at it yourself first. I did this and ended up restarting the language 3 times. This is generally a good thing because as you learn new ways, it might just be easier to restart.

My Journey

When I started with EZCode version 1, I just began with keywords. I started with print and built off of that. It originally didn't even include a parser. I eventually realized it was easier to start from scratch than to try to fix all of the bugs and include new features. I was able to improve my language with some new stuff I learned. I worked on that for ~6 months and then decided I needed to restart again. As of this post, I have been working on version 3 for nearly 2 months. This version has completely new syntax and just makes more sense. I wouldn't have been able to build it though if I didn't start with the basics.

Recap

I believe that building a programming language is a great way to learn how languages work. It removes the sense of magic in the compilers and interpreters that you use. I've learned that those are just programs that are made like any other application. It's a great experience and I would highly recommend it. If you want to learn more, here are some resources,