Vous êtes sur la page 1sur 4

The Magic behind Programming Languages

By Tehreem Ansari

Have you ever wondered: What goes behind a programming language?


How can the computer understand the Keywords?
How does it know that if its a loop, it should be executed n-number of time?
Or maybe, how was the programming language created in the first place itself?
We all know that computers are not magical, nor are programming languages spells that are cast
on computers to make them work. We see so many programming languages coming up each
year. Just like any human language, programming language too is created by humans, to make
computers understand what is to be done. They can be explained as the translators between
humans and computers.
Now the question comes, how are the programming languages created? Definitely your C, Java,
GO and so on, didnt just emerge out of nowhere.
Some computer languages are created using libraries of an already existing language, while some
have their own new libraries. All languages at the core are basically binary representation of 1s
and 0s that are on or off for the flip-flops or transistors.

How it all began:


Differential Engine, the first ever built computer executed tasks by changing the gears which
executed the calculations. Thus, the earliest form of a computer language was physical motion.
This was replaced by electrical signals where the programmers would manually rewire the
computer, but this manual process was tedious and difficult. Then came the switches for
addresses and functions. Each switch had a set of data word and memory address. If you wanted
the data to be entered, on the switch, else the switch is kept off.
Then came the punch cards, the position of the holes represented a particular bit position within a
word. These cards were put into the right sequence in a box, and then fed into a card reader,
which effectively converted them into binary code for the CPU.
The next thing was the Assembly Language this is where each instruction in the language
corresponds to a single instruction to the CPU. Its very low level language and extremely
verbose and labor intensive.

Assembly Language requires a program called the Assembler, to convert the assembly
language into "machine language"(0s and 1s). The very first assemblers were written in
"machine code" itself. It has a direct one-to-one correspondence with the raw language of the
computer itself.

Any language has 3 main things:


1. Lexical analysis :-

Converting computer keywords into tokens. Token is a string of


symbols/block of text which when grouped together defines
something.
For Example: When something like int num1=2; is defined, the lexical
analyzer translates it to something like:.

2. Syntax :- It simply means the structure and arrangement of the symbols.

(img from breakoutmentors.com)

3. Semantics :- It is the meaning of an instruction. For example, if you misspell a command,


it is a syntax error. If, you enter a legal command that does not make any sense in the
current context, it is a semantic error.

Now coming to the question, how are programming languages created?

Most of the programming languages, use C or hybrid of C language, for development. They use
a lexical analyzer/tokenizer like Flex to translate the keywords and a Parse Generator like
YACC. Parser generates a parse tree like the one given below:

These are languages that are used for one purpose - to describe the syntax of another language.
Sometimes when it comes to compiled languages, they are first implemented in C. Then the first
version of the language is used to create a new version, and so on.
Some of the languages influenced by C are: AMPL, AWK,csh, C++, C--, C#,Objective-C, BitC,
D, Go,Rust, Java, JavaScript,Limbo, LPC, Perl, PHP,Pike, Processing, Python,Seed7, Verilog
(HDL) (Source Wikipedia)
At the core is the Assembly Language. And example of Hello world in Assembly, in Java and
in Python is below:
Assembly language Hello World
(img from Wikipedia)

Java Hello World


(img from Wikipedia)

Python Hello World


(img from Wikipedia)

The codes written by a programmer in human readable form are called the source code. The
source code is either compiled or interpreted.
In compiled, the entire code is reviewed and then executed.
In an interpreter, you feed it the source code, that it reads [and converts into binary language]
line-by-line, executing as it reads/goes.
No matter in which language the source code is written, it ultimately goes to the lexer, from
where it gets converted to the machine code. Functions such as sin() are represented as a memory
address where its code block is. Keywords (like for) are converted to a list of byte codes, that
jump instructions compiled into assembly instructions and represented as binary.
So far we have seen how the computers enhanced, starting with physical motion, to a more
advanced form of systematic processing using softwares. And maybe in the future with the
imitation of human brain to create Supercomputers (see Blue Brain), the programming languages
will become just a 2nd language to people.

Vous aimerez peut-être aussi