Skip to content
how do you create a coding language?
Profile icon

im very confused can some one tell me?

You are viewing a single comment. View All
Profile icon

A programming language includes multiple steps. There are 2 different types of languages you can make: Dynamic and compiled.

I would suggest using C since C supports memory allocation and is usually the language used when it comes to writing programming languages

A dynamic language is what is called an "interpreted" language. A specific set of instruction repeat for each line of code, which is why interpreted languages are a bit slower than compiled.
A compiled language breaks down the code into binary and then executes that binary.

For interpreted languages, there are 4 main steps:
Syntax Tree,

The lexer goes through the file, character by character, and look for any type of punctuation, example '{' or '(', or any keyword, lets say 'function', then tokenizes it.
Tokenizing something means we assign the value of a punctuation or keyword to a specific keyword. So, if we were to write a language in C, we would assign a "token" to a value stored in an enum.
We "tokenize" punctuation and keywords so that it is easier and more relevant in the back-end of the language when it comes to needing to work with the punctuation and keywords

The lexer will feed straight into the parser. The parser is purely your imagination. The parser is where you setup the syntax for your language. The parser is where you use these tokens.

Next, the syntax tree. The syntax tree basically just stores all information, such as variable names, values, function names, functions args etc. The syntax tree is key to the runtime.

The runtime basically just checks over everything, and since it's the last step, I guess you can conclude that this is where the "magic" happens, such as having a variable a that has the value of 10 and you want to print it.
The runtime is by far the most important part of the interpreter due to the fact that it's the prime step of the language where everything actually starts to work. The lexer just tokenizes, the parser just sets up the language, then it's the runtime! The step that enables us to use function calls, print things, use if statements etc!

A compiled language has the first 3 steps of an interpreted language. A compiled language doesn't need a runtime primarily due to the fact that it doesn't need it. All of the instructions picked up by the parser that is being stored in the Syntax Tree is then executed into assembly then compiled down to binary, which is why a compiled language is much much faster.

So yeah, it is quite hectic reading about how to create a programming language, but it is not quite as hard when it comes down to the actual development of the language!