A computer can only execute instructions written in machine code (a sequence of zeros and ones). However, writing a program in machine code is a tedious process; therefore, programmers often write code in high-level programming languages like C++. The code that the programmer writes goes to a program called the compiler that converts it into machine code.
The following are some tasks that a compiler performs before converting source code to machine code:
A compiler goes over the entire code and groups the characters into strings called tokens. Common token names include operator and identifier.
A compiler checks for syntax error, i.e., if the tokens appear in incorrect order in the code.
Semantic analysis includes checking if variable usage is consistent with the rules of the programming language.
Free Resources