Compilers and Usage(Unsung Heros??)
Sumit Patnaik
Associate Consultant, Dynamic Software Engineer| Innovating Solution through Technology and Collaboration | Java ,OCI SQL Certificated ??
Hi,
This is a very generic topic, I tried to read some articles related to compiler. As such which we read in our bachelor's degree about Compiler Design. But I will try to make a series since it is long topics i might try some Algorithms on types of Compilers and How computer understands the code.
What is Compiler?
Going by book, It is tool in a software Development process which translates high level language to low level language(machine code) which computer understands. The process is as followed up:
The scanner (also known as the lexer) breaks down the source code into smaller units called tokens.
For example, the word “for” becomes the constant For, and the characters ... become DotDotDot.
The parser constructs a syntax tree from the tokens.
The syntax tree represents the hierarchical structure of the program.
The type checker ensures that expressions and statements adhere to the language’s type rules.It verifies that you’re not trying to add an integer to a string, for instance.
The compiler generates an intermediate representation (IR) from the syntax tree.
The IR simplifies further analysis and optimization.
This phase includes various optimizations, such as dead code elimination.
The goal is to improve the efficiency of the compiled code.
Finally, the compiler produces machine code (binary instructions) that the CPU can execute.
With the intriguing looking into article of Modular which uses MILR ,Java use JVM architecture ,i got into Article of Golang Internal:
Link reference : Golang Internal Compiler
I am taking the example same as the article which i went through the article
i := 4
until i == 0 {
i--
fmt.Println("Hello, until!")
}
Step-by-Step Exploration
The scanner tokenizes the input code.
Keywords like until become constants.
The parser constructs a syntax tree.
We’ll modify it to recognize the until statement.
We ensure that the until statement adheres to Go’s type rules.
We generate an intermediate representation (IR) for the until statement.
We apply any necessary optimizations.
Finally, we produce machine code for the modified program.
I know most of these topic are known to all but neglected by many, just a refresher , next article i will try to tell types of Lexical and how A* Algorithm keep the code completion work . Lot of stuff to learn and share.
Thanks for Reading??. Hope you like it.