Course Introduction to Programming

Compiler

Course's Page 5 min Text by
User Image
Matheus Henrique

In this class, we will learn basic concepts about the compiler; it will be divided into:

  • What is it?
  • Stages of the compilation
  • Cases of error

What is a compiler?

The compiler is the program that synthesizes code written in a programming language for the machine language. That is, after finishing the code, if it is correct according to the rules of the programming language, the compiler turns the code into a program, an executable file.

PS: a compiler can also be a program that translates code from one programming language to another ๐Ÿ˜‰.

Phases of compilation

The compilation process is usually divided into three parts:

  • Lexical analysis: the compiler checks whether the code uses the language symbols.
    Ex: in the sentence "I played ball" all the words are in English, so the sentence is lexically correct.

  • Syntactic analysis: the compiler checks if the code is written correctly.

  • Semantic analysis: the compiler checks if the code has logical meaning.
    Ex: in the sentence "played I ball", all the words are in English and written correctly, but the sentence makes no sense. Thus, although it is correct in lexicography and syntax, it is not correct semantically.

In cases of error

If at any stage of the compilation an error is found in the code, one of the main tasks of the compiler is to return an error report to the programmer to help him correct it quickly.

In this class, you learned a summary of how the compiler works, the phases of compiling and how it is important for fixing errors. It is important to note that a real compiler is much more complicated, but having a general notion of how it works will help you a lot.

See you next class ๐Ÿ˜„.