Compiler

esse quam videri
Revision as of 21:25, 21 June 2019 by Ishan115 (talk | contribs)
Jump to: navigation, search

Definition

A program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer.

What does this mean

Let’s say you’re coding in a piece of software (which often times have compilers built in), such as Microsoft Visual Studio. You want your computer to run your code when you click the “run” button. When you click that button, your computer reads the code you’ve written to make sure it can be converted into a language readable by your computer!

Relevance

Explanation

There are four major steps a compiler might run through to be sure your code is executable:

Scanning: reading one character at a time from the source code and keeps track of characters and their locations,

Lexical Analysis: The compiler converts the sequence of characters in the source code into a series of strings (known as tokens) which then matches those characters to symbols the computer can identify,

Syntactic Analysis: When you run your code, the compiler has to be sure that your code is readable - if it can’t understand what’s being written, then it won’t run, and that’s no good for anyone!

Semantic Analysis: Here, the compiler checks the tokens stored in relation to the language you’re coding in (ex. Python, C#) and parses your code to an intermediate language, called object code. This has instructions that tells a processor what to do when it encounters those tokens.

Finally, the compilers looks for optimization and generates the final object code that the computer reads.

Compile.gif

Credits: https://www.webopedia.com/TERM/C/compiler.html

Example

Compilers are what a computer uses to change the written code into what the computer uses.

What we write:

Console.WriteLine("Here is an example of what a complier is\n\n");

Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Do you see how the color of this text is different?\n\n");
Console.ResetColor();

Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("It is because I'm telling the compiler exactly what to do and how to do it.");
Console.ResetColor();

Console.WriteLine("Even the gap between the lines have to be specified to the compiler otherwise it wouldn't process.\n\n");

Console.WriteLine("One interesting thing about the compiler is that it doesn't care about how much space is there between each line of code, because it omits whitespace / blank space." +
" But, if there's space in a string, it would not omit the whitespace because the space itself is a character. ");

Console.ReadLine();

What the compiler generates for us:

Here is an example of what a complier is
Do you see how the color of this text is different?
It is because I'm telling the compiler exactly what to do and how to do it.
Even the gap between the lines have to be specified to the compiler otherwise it wouldn't process.
One interesting thing about the compiler is that it doesn't care about how much space is there between each line of code, because it omits whitespace / blank space. But, if there's space in a string, it would not omit the whitespace because the space itself is a character.

Resources

https://www.webopedia.com/TERM/C/compiler.html

External Links