Programming: How Are Programming Languages Made? [2023]

How are programming languages made? How was the first programming language created? Can you really program a programming language?

Without programming, all of our fancy technology wouldn’t exist. But how are programming languages even made? And how was the first programming language created if there wasn’t one before?
Keep reading to get an answer to those questions!

How are Programming Languages Made?

In a nutshell:

Programming languages are created using already existing languages like C or C++. Basically, creating a new programming language is like making a regular computer program. The main thing you are going to work on is tokenizing source code and parsing it to a compiler/interpreter that optimizes the code and turns it into machine code using the base language (e. g. C++).

How Programming languages are made

Besides the compiler/interpreter, there usually are two additional things that are programmed even before the compiler/interpreter. However, they are not necessarily needed as there are other ways of doing their job.

The first one is the Lexer. It takes the source code and converts it into an ordered list of tokens. Tokens are just keywords, symbols, operators, or numbers (e.g. if, +, -, etc.)

Next, the Parser gives the tokens a bit more structure and turns them into a tree of nodes (a so-called parser tree).

Now, the compiler/interpreter can turn the tokens into instructions and make machine code out of them using the base language. However, you do not need to write your own compiler or interpreter. Instead, you can just parse the tokens to an already existing compiler (e. g. turn the tokens into Python code)

When writing a new language, the programmer has to define syntax, basic keywords, and a lot of other things.
So before a programmer starts to write a new programming language, he has to think about the following things:

Why? - What's the goal?

The first thing that needs to be clarified is the goal of the new language. – What is its purpose?
Depending on what the programming language should be used for, it may have a completely different syntax and different libraries than a language that serves another purpose.

For example, you’ll need completely different libraries if you want to create a language for graphical applications rather than console applications.

The platform

Next, you need to decide on which platforms your code is going to run.  – Is your language only going to be used for windows applications, or for Linux and mobile platforms too?

Of course, the interpreter needs to be able to run on that platform, and the compiler needs to be able to generate a file that the platform can deal with (e. g. .exe on Windows).

Compiled or interpreted?

The next thing would be to think about whether the language should be compiled or interpreted.

Compiled languages are translated into machine code before the execution. Hence, the user of the application doesn’t need a compiler to be installed.

Interpreted languages are translated into machine code at runtime. To run the code, every user needs to have the interpreter installed.

What tokens (keywords) do I need?

Every programming language has got a set of predefined fixed tokens (keywords) like if, while, var, etc. They make up the basic syntax.

At this stage, the programmer has to decide how to name the tokens needed for a complete programming language.

OOP or functional programming?

Now, the programmer has to decide whether the programming should be object-oriented or function-oriented.

Object-oriented languages use classes to combine functions (methods), which define the behavior, and variables, which define properties, into an object. An example of an object-oriented programming language is Java.

Functional languages don’t use classes to create objects. They just have their functions and variables. For example, Python is a mainly functional programming language.

The syntax

The next step is to define the syntax of the programming language. When using the new programming language, the programmer has to strictly follow it. Otherwise, the compiler/interpreter wouldn’t be able to understand the code and would generate an error.

It needs to be decided whether to use semicolons, colons, brackets, and how symbols and tokens need to be arranged.

What libraries am I going to use? - Do I have to create my own?

To create a programming language, the programmer also needs to use libraries of the base language when writing the compiler/interpreter. 

Also, he has to create some standard libraries for the programming language he is creating. For example, the programming language needs basic libraries for printing text to the console, gathering user input, and doing a bit more advanced math.

The name

Lastly, you have to choose a name for your new programming language. Of course, you can choose a name before beginning to create the programming language, but I suggest doing it as a final step as you’ll know more about the characteristics of the programming language then.

How was the First Programming Language Created?

If you build new programming languages based on already existing ones, then how was the first programming language created when there wasn’t one before?

The first ‘language’ is hardwired into the processor (an electrical circuit consisting of electrical switches called transistors). It is called Machine Code. The Machine Code consists of only ones (on) and zeros (off) called bits.
Specific combinations of bits perform a specific task on the processor (instructions are hardwired). In 1949, the first programming language Assembly was created to create synonyms for those combinations that are easy to understand for humans.
To make this work, the first assembler that could translate Assembly language into machine code had to be written directly in machine code.

Based on Assembly, people were now able to create more high-level languages.

Again in short:
The first programming language was written in machine code.

Why Should YOU Create a New Programming Language

Obviously, you’ll learn about how programming languages work and what’s going on inside your computer when you compile or run code.

Additionally, your coding skills will improve a lot because creating a new programming language is everything but easy, hence, is really good practice.

Also, it is a lot easier to work with your own programming language than with others because it suits your coding style and preferences the best, and you know exactly what you need to do. 

Summary

Programming languages are written in already existing languages like C++. However, before you can get started with programming a new language, you have to consider a lot of important things.

In 1949, the first programming language was written directly in machine code. Its name is Assembly.

Thanks for reading!

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *