How to Understand C++ Compilers
A compiler is a program that translates source code in human-like language into machine instructions. The end product is an executable file. Compilers generate more efficient programs. They can build library files that hide implementation so that those can be linked into the main program. C++ compilation is a process that involves several phases.
Instructions
-
-
1
Understand the preprocessor phase. C++ compilers begin compilation by running a simple program called the preprocessor. The preprocessor converts the preprocessor directives and writes the result to an intermediate file. Preprocessor directives are formulas that increase readability in source code and save typing.
-
2
Comprehend the scanning phase. This is also called the lexical analysis phase. Here, source code is broken into its ultimate units called tokens. The token can be a keyword, an identifier or a symbol name.
-
-
3
Identify the parsing phase. This is also known as "syntactic analysis." Here, the linear sequence of the tokens from the previous phase is reorganized the into a structure called a parse tree. A parse tree is a structure built by the rules of the formal grammar that defines the syntax of C++.
-
4
Learn about the semantic analysis phase. Here the compiler augments the parse tree and builds the symbol table. This phase involves type checking (prevention of errors related to type matching), object binding (connection of definitions to declarations for functions and classes), definite assignment (initialization and operator overloading processing) and the identification of warnings and errors.
-
5
Grasp the machine-independent optimization phase. Here a program called a global optimizer is used to produce intermediate code that is optimized for better efficiency.
-
6
Review the code generation phase. This is where the intermediate code is transformed into the machine language of the system. This can be either assembly language or machine language. If it's assembly language then the assembler, a program, is executed. In both cases the result is object modules having as extension, ".obj."
-
7
Become familiar with "machine-dependent optimization." In this phase the machine code that has been generated is optimized even more.
-
8
Familiarize yourself with linking. Here, a program called the linker combines the optimized object modules into an executable program with the familiar ".exe" extension that can be loaded into memory and run by the operating system. The linker resolves references to functions across files such as object modules or library files.
-
1