Skip to content
Sign upLog in
← Back to Community
Can anyone please tell me how to make a programming language
Profile icon
CuriousMonkey

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

Answered by MocaCDeveloper [earned 5 cycles]
View Answer
Voters
Profile icon
JustACloud
Profile icon
CuriousMonkey
Comments
hotnewtop
Profile icon
MocaCDeveloper

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!!

Profile icon
CuriousMonkey

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

Profile icon
MocaCDeveloper

@CuriousMonkey
Yep I should be free on Saturday!

If not I will let you know, and if you want to collaborate any sooner let me know!

Profile icon
CuriousMonkey
Profile icon
CuriousMonkey

i am making a repl right now for our programming language i will add you in a [email protected]

Profile icon
CuriousMonkey

should i make it in c or c++

@MocaCDeveloper

Profile icon
CuriousMonkey

i will make it in c++ becuase c++ can still have c code in it

@CuriousMonkey

Profile icon
CuriousMonkey

you know i could actualy do it now i finished school like 2 seconds ago

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
Sorry I was at school then I had to work late!

Also, I would recommend C to have some more low-level ideals such as memory management! That and I really don't know/like C++

Profile icon
CuriousMonkey

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

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
Ping me when you're online and ready to work!

Profile icon
CuriousMonkey

ok im on right now but im in math class maybe in like 50 min

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
Alright just ping me when you available to code!

Profile icon
CuriousMonkey
Profile icon
MocaCDeveloper

@CuriousMonkey
Alright I will head over! I am currently in school though but I will be available to code for the next hour!!

Profile icon
MocaCDeveloper

@CuriousMonkey
Ready to code??

Profile icon
CuriousMonkey

OMG IM SOOOOO SORRY I COMPLETELY FORGOT TO CHECK MY REPL OMG SOOOOO SORRY :( :( :(

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
no it's fine it's no problem!
Nothing to be sorry about!

Profile icon
CuriousMonkey

ty we can do it at 2:30 pm pacific time

@MocaCDeveloper

Profile icon
CuriousMonkey

wassup im done with school want to do now or are you busy

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
I am about to go to work :/

Profile icon
MocaCDeveloper
Profile icon
CuriousMonkey

oh ok how about tommorrow at the same time we did yesterday

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
Yes perfect!!

Profile icon
CuriousMonkey

want to do now?

@MocaCDeveloper

Profile icon
MocaCDeveloper
Profile icon
MocaCDeveloper
Profile icon
CuriousMonkey

wait yesterday we said we would do saturday cuz im kinda busy with school :(

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
Ohh yeah i forgot sorry!!

I am able to do it now and from 4-10pm tonight though if your free!

Profile icon
CuriousMonkey

hmmm well i am going to my friends house during that time(fwi he also does repl)

@MocaCDeveloper

Profile icon
CuriousMonkey

so lets do tommorow :)

@CuriousMonkey

Profile icon
MocaCDeveloper
Profile icon
CuriousMonkey

hey actually are you free right now cuz i can do like the whole day.

@MocaCDeveloper

Profile icon
MocaCDeveloper

I’m free now to 430!

@CuriousMonkey

Profile icon
CuriousMonkey

ok lets do now

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
alright I am heading over!!

Profile icon
CuriousMonkey

wanna code now

@MocaCDeveloper

Profile icon
MocaCDeveloper

@CuriousMonkey
I am free now!

Profile icon
MocaCDeveloper

@CuriousMonkey
You free?

Profile icon
CuriousMonkey

i can do tommorow at this time

@MocaCDeveloper

Profile icon
MocaCDeveloper
Profile icon
SixBeeps

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.

Profile icon
CuriousMonkey

oh so thats why its called ast [email protected]

Profile icon
Coder100

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!

Profile icon
MocaCDeveloper

@Coder100
Usually you would want to stay away from Python. I don't know so much about JavaScript, I've seen some languages made in it, but I don't really know how fast it is.

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.

Profile icon
Coder100
Profile icon
Coder100

python is bad ok want to work on the election

@MocaCDeveloper

Profile icon
MocaCDeveloper

Hi! :)@Coder100

Profile icon
MocaCDeveloper

@Coder100
Lol sure, and Python is good for many things EXCEPT programming language development

Profile icon
MocaCDeveloper

@Coder100

Lets get to work, my good sir!

Profile icon
Coder100
Profile icon
CuriousMonkey

thx but i want to make a language with something old fashioned like c and c++ you know

@Coder100

Profile icon
MocaCDeveloper

@Coder100
Election Poll app?