Recall & Review
beginner
What is the main purpose of the lexical analysis phase in compilation?
Lexical analysis breaks the source code into tokens, which are meaningful sequences like keywords, identifiers, and symbols. It removes whitespace and comments.
Click to reveal answer
beginner
What does the syntax analysis (parsing) phase do?
Syntax analysis checks if the tokens follow the grammar rules of the language and builds a tree structure called the parse tree or syntax tree.
Click to reveal answer
intermediate
Explain the role of semantic analysis in compilation.
Semantic analysis ensures the code makes sense logically, like checking variable types and if variables are declared before use. It adds meaning to the syntax tree.
Click to reveal answer
intermediate
What happens during the intermediate code generation phase?
The compiler creates a simple, machine-independent code from the syntax tree. This code is easier to optimize and translate into machine code later.
Click to reveal answer
intermediate
Why is the optimization phase important in compilation?
Optimization improves the intermediate code to run faster or use less memory without changing what the program does.
Click to reveal answer
Which phase of compilation converts source code into tokens?
✗ Incorrect
Lexical analysis breaks the source code into tokens.
What does the syntax analysis phase produce?
✗ Incorrect
Syntax analysis produces a parse tree representing the program's structure.
Which phase checks for type errors and variable declarations?
✗ Incorrect
Semantic analysis checks for logical correctness like types and declarations.
What is the main goal of the optimization phase?
✗ Incorrect
Optimization improves code speed or memory use without changing its meaning.
Which phase produces machine-independent code?
✗ Incorrect
Intermediate code generation creates code that is not tied to any specific machine.
Describe the main phases of compilation and their roles.
Think about how the compiler transforms source code step-by-step.
You got /6 concepts.
Why is semantic analysis important after syntax analysis?
Syntax checks form, semantic checks meaning.
You got /4 concepts.