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
Most compilers use what is called an Abstract syntax tree to create instructions that a computer can follow. I haven't worked on my own language before, but I've seen them being implemented with this plenty of times.
oh so thats why its called ast [email protected]
Well, what language?
This is a great tutorial
ig this works
this is cool
python tutorial
node.js tutorial
Whatever you use, it's not easy to make a language, so perservere!
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.
python is bad ok want to work on the election
Hi! :)@Coder100
Lets get to work, my good sir!
thx but i want to make a language with something old fashioned like c and c++ you know
@Coder100
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.
Compiled programming languages
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!
Interpreted programming languages
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!
How to make a language(interpreted!)
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!
What is a 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!
What is a Token?
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!
The parser
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
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
The Runtime
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
@MocaCDeveloperIf not I will let you know, and if you want to collaborate any sooner let me know!
ok thx
@MocaCDeveloperi am making a repl right now for our programming language i will add you in a [email protected]
should i make it in c or c++
@MocaCDeveloperi will make it in c++ becuase c++ can still have c code in it
@CuriousMonkeyyou know i could actualy do it now i finished school like 2 seconds ago
@MocaCDeveloperAlso, I would recommend C to have some more low-level ideals such as memory management! That and I really don't know/like C++
oh ok well c++ is just c but with OOP and instead of malloc and calloc and free there is new and delete but we can do c
@MocaCDeveloperok im on right now but im in math class maybe in like 50 min
@MocaCDeveloperim DONe
@MocaCDeveloperOMG IM SOOOOO SORRY I COMPLETELY FORGOT TO CHECK MY REPL OMG SOOOOO SORRY :( :( :(
@MocaCDeveloperNothing to be sorry about!
ty we can do it at 2:30 pm pacific time
@MocaCDeveloperwassup im done with school want to do now or are you busy
@MocaCDeveloperI am so [email protected]
oh ok how about tommorrow at the same time we did yesterday
@MocaCDeveloperwant to do now?
@MocaCDeveloperwait yesterday we said we would do saturday cuz im kinda busy with school :(
@MocaCDeveloperI am able to do it now and from 4-10pm tonight though if your free!
hmmm well i am going to my friends house during that time(fwi he also does repl)
@MocaCDeveloperso lets do tommorow :)
@CuriousMonkeyhey actually are you free right now cuz i can do like the whole day.
@MocaCDeveloperI’m free now to 430!
@CuriousMonkeyok lets do now
@MocaCDeveloperwanna code now
@MocaCDeveloperi can do tommorow at this time
@MocaCDeveloper