ITPEC FE Morning October 2020 Question 17
Topic: Software
Among the processes that are performed by a compiler for a procedural language, which of the following is the process that is performed first?
Explanation
Lexical analysis — the compiler first reads the source text as characters and groups them into tokens, which every later phase works on.
The compilation phases run in this order:
- Lexical analysis: characters into tokens (keywords, identifiers, operators, literals)
- Syntactic analysis (parsing): tokens into a parse tree, checked against the grammar
- Semantic analysis: type and declaration checks, meaning of each construct
- Optimization: improving the intermediate code
- Code generation: producing the object code
Answer (a)
Why not others:
- •(b) Optimization — works on intermediate code, so it comes after all three analysis phases
- •(c) Semantic analysis — needs the parse tree, so it follows syntactic analysis
- •(d) Syntactic analysis — needs tokens as input, so it follows lexical analysis
Key rule: Each phase consumes the output of the one before: characters, then tokens, then a parse tree, then checked intermediate code, then object code.
Software · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.