Compilation process Flashcards
How many steps are there in the compilation process of a program?
Six total steps, with an optional extra one.
Name all of the steps in the compilation process of a program.
- Lexical analysis (scanning)
- Syntax analysis (parsing)
- Semantic analysis
- Immediate code generation
- Code optimization
- Code generation
- Extra: Linking
Explain the purpose of the first step of the compilation process.
The lexical analysis (scanning) reads the source code into BT characters and groups them into tokens.
Explain the process of the first step of the compilation process.
The lexical analysis process consists on having the lexer (or scanner) identify elements such as keywords, identifiers, operators, constants, and other syntactic elements, while discarding white spaces and comments.
What is the output of the first step of the compilation process?
Stream of tokens
Explain the purpose of the second step of the compilation process.
On the Syntax analysis (parsing), the stream of tokens is checked for whether the code follows the grammatical rules (syntax).
Explain the process of the second step of the compilation process.
On the syntax analysis, the parser constructs a parse (or syntax) tree, which represents the grammatical structure of the program. It identifies syntax errors, too.
What is the output of the first step of the compilation process?
Parse tree
Explain the purpose of the third step of the compilation process.
On the Semantic analysis, the meaning or semantics of the program is checked.
Explain the process of the third step of the compilation process.
On the Semantic analysis, a verification of type compatibility is done, if variables are declared before use, and other semantic checks are performed. Information about the program’s meaning is gathered.
What is the output of the third step of the compilation process?
Annotated syntax tree (AST)
Explain the purpose of the fourth step of the compilation process.
On the Immediate code generation, an intermediate representation (IR) of the source code is generated by the compiler.
Explain the process of the fourth step of the compilation process.
On the Immediate code generation, the AST is translated into an IR by translating arithmetic, logical, and relational expressions into intermediate code, such as three-address code, quadruples, or triples. Variables get assigned values. Control flow statements are handled.
What is the output of the fourth step of the compilation process.
Intermediate code (IR)
Explain the purpose of the fifth step of the compilation process.
On the Code optimization, there is an attempt to improve the performance and efficiency of the generation code by applying various optimization techniques.
Explain the process of the fifth step of the compilation process.
On the code optimization, transformations are performed on the IR by the optimizer. Optimizations could be constant folding, dead code elimination, and loop optimization.
What is the output of the fifth step of the compilation process?
Optimized intermediate code.
Explain the purpose of the sixth step of the compilation process.
On the Code generation, the optimized intermediate code is translated into the target machine code.
Explain the process of the sixth step of the compilation process.
The code generator selects appropriate machine instructions for each IR instruction and allocates registers for variables.
What is the output of the sixth step of the compilation process.
Target machine code or assembly code.
What is the optional, extra step (seventh) of the compilation process?
Linking.