top of page

The Needs of a Compiler: How It Translates High-Level Languages into ML

You may have studied binary language in your computer textbooks. This language is the only language that a computer can understand. In binary language, one should write the programme using only 0s and 1s.

It means to make a command to your computer, like to open or create a file; you should write a whole program containing only 0s and 1s. But are you doing that today?


Of Course not; it just takes a few clicks to open or create any file. However, the computer still gets the commands in the binary language in the back end. It means the language of computer inputs is still the same, but we have developed other ways of creating programmes which are more human-friendly and allow us to create more complex programmes. But how is it possible for us to do so?


One thing you should know is that compilers played an important role. So let's learn how the compilers changed the way we code today.


What is a compiler ?


A compiler is a program that helps translate a source code written in a high-level language into a machine language. This conversion from high-level language to a machine language is important as a computer can only understand codes in machine language.


Why do we need a compiler?


As you may have assumed, writing programs in the binary language is hard for human capabilities. To tackle this problem, humans came up with high-level languages. Writing programmes in high-level languages is comparatively easier than writing the same programme in machine language like binary.


Humans can easily understand programmes written in high-level languages. But it cannot be understood by a computer. So, the gap between these two types of languages is filled through a compiler. For example, if you have written a Python programme, then with an ide Python compiler, you can translate the program for the computer. Moreover, you will also be able to know if the programme is doing exactly what you want or not.


How does a compiler work?

A compiler has a complete process of translating a high-level language code into a machine language code. It follows several steps to translate, which include analysis, optimization and generation of the code.


Steps followed by a compiler after submitting a source code -


Lexical Analysis - Firstly, the compiler runs the source code through a lexical analysis. The compiler breaks the code into smaller parts which are called lexemes. After that, the compiler creates a sequence of tokens. Each token describes the purpose of the respective lexeme.


Syntax Analysis - Now, the sequence of tokens generated during lexeme analysis is used to make an Abstract Syntax Tree. The AST is the logical structure generated for the programme. If the structure contains any syntax error, the process will get stopped resulting in a compilation error. If such things happen, the developer must check the source code for the error highlighted by the compiler continue reading...

Recent Posts

See All

Comments


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page