+ 3
Can anyone say that how programming languages were made?
Whenever I code, I usually get amazed that how a few lines can create a great software, we code in different languages to make programs , but how a thing was made that can do this?
4 Answers
+ 7
Where, is a long long story. There are basically two types of programming languages. Compiled and interpreted ones. Also are ones that run on a virtual machine, but this is another story.
Compiled ones needs a lexical analyser and a linker, because compilation is made typically in two phases.
Interpreted ones are parsed one instruction at a time when the application is running
I tell you, is a long long story đ
+ 5
There are two types of programming languages, interpreted and compiled.
But the way of creating them is not that different. Even most interpreted languages compile down into virtual machine instructions, instead of real machine instructions like compiled languages.
Simply put, there are 4 phases in a compiler/interpreter.
1 - Lexing
2 - Parsing
3 - Syntax check
4 - Compiling
Lexing: in this phase, you create tokens usually out of a string (Like strings, numbers, keywords etc.)
Parser: in this phase, you take all the tokens and then generate an AST (Abstract Syntax) tree using them.
*
/ \
+ 7
/ \
5 6
Syntax check: in this phase, you check if every node in ast tree is correct. For example an addition node should have at least two nodes.
Compiling: in this phase, you take the ast tree, and compile every node recursively into a series of (virtual maybe) machine instructions. The given example ast would look like:
Load 5
Load 6
Add
Load 7
Multiply
Dead simple
+ 3
Mustafa Yıldız Fantastic summary!
It reminded me of this video which quite impressively uses some amazing visuals to illustrate these phases while drawing the connection to how programming languages are implemented as well as created.
https://youtu.be/QXjU9qTsYCc