YARDSTICK INTERNATIONAL COLLEGE
UNDER GRADUATE PROGRAM
2016E.C Final Exam
General Information:
1 Program Under Graduate Studies Program
2 Course Compiler design
3 Course Code
CoSc4102
4 Instructor Mr. Adane Mulie
5 Time Allowed 90 minutes
6 Exam date Saturday , Jan 3/2017 E.C
Name: __________________________________ Id. No __________________ Section ______
Signature _____________
General Instructions:
Read the Instructions carefully before you start to answer.
Your exam booklet contains three parts
Give your answer for all questions only on the answer sheet provided.
Clear and neat work is rewarding.
Don’t use mobile and any electronic device during exam except adding calculator.
Don’t hand any material related with the course during exam.
Don’t disturb others in any means.
If you face any problem or have questions please call the invigilator quietly.
Leaving the exam room before 30 minutes is not allowed.
Any attempt to cheat has no excuse and nullifies your result.
Do not turn the page until you are told to do so.
PART I: SAY TRUE IF THE STATEMENT IS CORRECT ELSE FALSE (2pt each)
1. A compiler supports high-level language instead of direct machine instruction.
2. Heuristic-based search for optimization is one of the scenes of artificial intelligence.
3. Lexical analysis is the process of converting a sequence of characters into a sequence
of attributes.
4. CFG is used to specify the structure of legal programs.
5. A sequence of replacements of non-terminal symbols to obtain strings/sentences is
called a derivation.
PART II: CHOOSE THE BEST ANSWER (2pt each).
1. Which of the following is not a phase in the standard compilation process?
A) Lexical Analysis C) Code Optimization
B) Syntax Analysis D) Code Execution
2. Which one of the following data structures is primarily used by a parser in syntax
analysis to store the parse tree?
A) Stack C) Linked List
B) Queue D) Tree
3. Which of the following is not a type of grammar used in compiler design?
A) Context-Free Grammar (CFG) C) Unrestricted Grammar
B) Regular Grammar D) Recursive Grammar
4. Which of the following is the correct order of phases in a typical compiler?
A) Lexical analysis → Syntax analysis → Semantic analysis → Code generation
B) Lexical analysis → Code generation → Semantic analysis → Syntax analysis
C) Syntax analysis → Lexical analysis → Semantic analysis → Code generation
D) Code generation → Syntax analysis → Semantic analysis → Lexical analysis
5. Which of the following can be an issue if a compiler does not perform semantic analysis
properly?
A) Incorrect tokens D) Poor optimization of code
B) Ambiguity in grammar
C) Type mismatches or
undefined variables
2|Page
6. Which of the following is not a role of the lexical analyzer in a compiler?
A) Scanning the source code C) Checking the syntax of the
program
B) Identifying tokens in the source
code D) Removing comments and
whitespace
7. What is the purpose of intermediate code generation in a compiler?
A) To produce an executable file
B) To optimize the source code
C) To represent the program in a machine-independent form
D) To check for syntax errors
8. What is a syntax-directed translation (SDT) used for in a compiler?
A) To perform semantic analysis
B) To generate intermediate code based on the syntax tree
C) To optimize the intermediate code
D) To detect syntax errors in the source code
9. Which of the following is a primary goal of code optimization in a compiler?
A) To ensure correct semantic analysis
B) To reduce the size and improve the efficiency of the generated code
C) To convert the intermediate code into machine code
D) To check for syntax errors in the source code
10. Which of the following is the primary role of the semantic analyzer in a compiler?
A) To detect and handle syntax errors
B) To check type consistency and variable scope
C) To optimize the intermediate code
D) To convert the intermediate code into machine code
3|Page
PART III: GIVE SHORT AND PRECISE ANSWER (5 each)
1. Explain the role of the lexical analyzer in a compiler.
2. What is the purpose of semantic analysis in a compiler?
3. What is an abstract syntax tree (AST), and why is it used in compilers?
4. What is the role of intermediate code generation in a compiler?
4|Page