Can anyone please tell me how to make a programming language
hi everyone i have seen that lots of ppl have made programming languages on repl and i have been inspired to try and make one. ONE PROBLEM idk how to make one xD
YES!! Finally! Someone who is capable of actually wanting to do it, and KNOWS the language to do it in!!!!
I have helped many many people on how to make a programming language, and I am one lucky duck to finally run into someone who wants to make one, and who also knows C!!
I want to get one thing out though: You need to have a broad idea of what you language is going to be used for, and what type of syntax you are going to want for it, as well as it's complexity.
Programming languages are sorted into 2 categories: Interpreted and Compiled.
A compiled programming language is a language that is turned into binary, then is executed.
For a compiled language, you will have normal C code that gathers the whole file, tokenizes everything, then the compiler will do the rest!
A interpreted programming language is a language ran line-by-line repeating each action for every line which is why choosing to interpret a language is a bit slower than compiling(for example: Python)
Usually this is what you want to start with if you're new to creating a programming language. This is what I am still working with and I started programming language dev about 4 months ago!
Now, most steps for both compiled and interpreted languages are the same, the only difference is an interpreted language has a runtime and goes straight from a AST to the runtime.
I will explain what an AST is later!
First off, you are going to want to read a source file that contains the code.
After this, you are going to want to create what is called the Lexer!
A lexer goes through the file line by line(usually character by character), and is capable of picking up keywords and punctuation needed.
The Lexer will also "tokenize" keywords and punctuation found!
A token is just something that can resemble a keyword, or punctuation, in our language for our interpreter written in C!
The token will just be something within the C code! The keyword, or punctuation, in the language will be what decides what the "token" is!
Now, since the Lexer tokenizes everything from keywords to punctuation, how do we use those valuable tokens?
The parsing step of a programming language is the step where syntax is introduced and where the AST starts!
In this step, you will use each token being passed through the parser and check it. Usually, you will have a function in the parsing step that checks the current token for a certain keyword(such like a function declaration etc), then it continues onto a function that parses the correct syntax for that given keyword!
So, basically, the parser parses the correct syntax for each keyword picked up.
Tokens picked up in the Lexer(for either keywords or punctuation) will be sent straight to the parser
The AST of the language is just the Syntax Tree. It stores all variable names, function names, variable values etc.
The syntax tree is what makes the language come alive. The AST is used within the runtime!
Since the AST stores all basic information(variable names, function names etc), the next step is in the runtime!
Note: The Syntax Tree(AST) is setup within the parser. Everytime the parser parses through a keyword, the information will be picked up and put into the AST
Within this step, you make the language come alive.
The Runtime will go over each ideal within the AST. For each ideal, it will do a specific task!
Usually it just stabilizes the information.
Lets say there was a variable declaration, the AST would by default have the variable name and value, so all you'd have to do to check the ideals of the variable is just return the AST in the step where it checks for the variable.
I mean, you could of course do some stuff to check before continuing on, but that is usually not the case
So, a programming language is made up of 4 parts: Lexer, Parser, Syntax Tree and Runtime.
The 2 main parts of the language is going to be the Lexer and Parser.
The Syntax Tree and Runtime are just what allows the language to actually work. The Lexer and Parser are the 2 ideals that tokenize and setup the syntax that make the language what it is.
Now, while this doesn't really answer exactly how to make a programming language, it gives a brief description of each step.
The lexer: Goes through the file character by character picking up keywords and tokenizing them as well as punctuation
The Parser: Goes through each token and checks for certain keyword tokens to setup the syntax. Usually that is all the parser will do, setup syntax for certain keywords because punctuation is kinda a secondary thing in a langauge.
AST(Syntax Tree): This stores all information from variable names to variable values, function names to function values etc!
Runtime: Goes over each ideal within the AST(Syntax Tree) and then evaluates each part of the language!
The only real way you can tell the runtime is working is when you print a variable out to the screen. Other than that, if you just have a variable declaration you just gotta trust that the runtime is working!
That is why the runtime is probably a tougher step to a programming language because you really don't know that it's working until you do something in your language that generates outcome!
The parsing step and lexing step will be easier since you will be able to tell it is working due to the fact that is where your language will be more prone to errors due to typos, wrong punctuation etc!
Note, it is a bit difficult to explain step by step since it is allot to take in. I will gladly collaborate with you if you want a 1 on 1 practice!
If you want to collaborate with me so I can teach you 1 on 1 how to make a programming language, just let me know!
I am always open and willing to teach anyone who is wanting/willing to learn!!
OMG THANK YOU SOO MUCH I AM ALSO LUCKY TO ACUTALLY FIND SOMEONE WHO ACTUALLY KNOWS C too xD ummm are you free on saturday 1:30 pm pacific time. also this tutorial you just gave was AMAZING only thing i need to do is actualy you know type the code for it which i am hoping you will show me the basics of on Saturday. also again THANK YO SOOO MUCH :D@MocaCDeveloper
But Python is usually the language you try and stay away from when it comes to creating a programming language due to the fact Python is a automation language, data science language, dynamic language and very high level and slow.