AI3, FIN
1
UU – COM-4022
Artificial Intelligence
and Compiler Design
Summative Assessment 3 Overview of Compilation, Code Generation and Optimization & Previous Topics
Introduction
Summative Assessment 3 will test your knowledge on the aspects of compiler design as well as
other topics that have been covered throughout the module. In addition, you will be tested on your
ability to apply concepts from these topics with practical lab exercises.
Summative Assessment 3 (Final Assignment) is worth 40% of the final module
grade and is due at the end of Week 7 by 11.59 p.m. (23.59 hours) VLE (UTC).
Please submit your work using the “Summative assessment 3 submission link” on the
module’s VLE page
Assessment guidelines
Summative Assessment 3 will marked out of 100 points consist of three parts:
Part 1: Multiple Choice Questions (MCQ’s) [20 points]
o 20 multiple choice questions, each question is worth 1 point
o A single choice is required for each question
Part 2: Logical questions [20 points]
o 2 questions, each question is worth 10 points
Part 3: Short answers [20 points]
o 5 questions, each question is worth 4 points
o Answers must be short but must cover the topic with an appropriate level of depth
o The maximum word length must be between 150-200 words
o Where necessary references should be included using the required referencing style
(APA)
Part 3: Lab Tasks [40 points]
o Multiple practical exercises that require knowledge acquired from all the Topic
Overviews and the associated Practical Lab Exercises
o You will need to provide screenshots and/or program code of the exercises as proof
of completion
2
UU – COM-4022
Artificial Intelligence
and Compiler Design
Assessment criteria
Please refer back to the assessment guidelines for the explicit breakdown of marks (points) for
summative assessment 3.
The overall marking of the overall assessment for all sections will be based on the following
criteria:
The ability to demonstrate an understanding of the chosen topic(s)
The ability to synthesize ideas, develop strong arguments, summarize key ideas and draw
effective conclusions.
The ability to follow the requirements
The ability to effectively support ideas using relevant references.
The ability to demonstrate an adherence to good grammar, spelling and logical structure
3
UU – COM-4022
Artificial Intelligence
and Compiler Design
Part 1: MCQ’s (20 points)
1. What is a compiler?
a. System program that converts instructions to machine language
b. System program that converts machine language to high-level language
c. System program that writes instructions to perform
d. None of the mentioned
2. Which of the following is a stage of compiler design?
a. Semantic analysis
b. Intermediate code generator
c. Code generator
d. All of the mentioned
3. What is the use of a symbol table in compiler design?
a. Finding name’s scope
b. Type checking
c. Keeping all of the names of all entities in one place
d. All of the mentioned
4. Which of the following error can a compiler check?
a. Syntax Error
b. Logical Error
c. Both Logical and Syntax Error
d. Compiler cannot check errors
4
UU – COM-4022
Artificial Intelligence
and Compiler Design
5. A programmer, writes a program to multiply two numbers instead of dividing them
by mistake, how can this error be detected?
a. Compiler or interpreter
b. Compiler only
c. Interpreter only
d. None of the mentioned
6. Users write the programs in which language?
a. Low-level Language
b. High-Level Language
c. Decimal-Format d. Middle-Level Language
7. Which computer program accepts the high-level language and converts it into
assembly language?
a. Interpreter
b. Linker
c. Assembler
d. Compiler
8. Does the compiler program translate the whole source code in one step?
a. No
b. Depends on the Compiler
c. Don't Know
d. Yes
5
UU – COM-4022
Artificial Intelligence
and Compiler Design
9. Which of the following file is an output of the assembler?
a. Program file
b. Object file
c. Data File
d. Task File
10. Which tool is used for grouping of characters in tokens in the compiler?
a. Parser
b. Code optimizer
c. Code generator
d. Scanner
11. What is the linker?
a. It is always used before the program execution.
b. It is required to create the load module.
c. It is the same as the loader
d. None of the above
12. Parsing is categorized into how many types?
a. Three types
b. Four types
c. Two types
d. Five types
6
UU – COM-4022
Artificial Intelligence
and Compiler Design
13. In which parsing, the parser constructs the parse tree from the start symbol and
transforms it into the input symbol.
a. Bottom-up parsing
b. Top-down parsing
c. None of the above
d. Both a and b
14. What is the action of parsing the source program into proper syntactic classes known
as?
a. Interpretation Analysis
b. General syntax analysis
c. Syntax analysis
d. Lexical analysis
15. What does a bottom-up parser generate?
a. Rightmost derivation in reverse
b. Rightmost derivation in reverse
c. Leftmost derivation in reverse
d. Leftmost derivation
16. What is the bottom-up parsing method also known as?
a. Predictive parsing
b. Shift reduce parsing
c. Recursive descent parsing
d. None
7
UU – COM-4022
Artificial Intelligence
and Compiler Design
17. The output of the lexical analyzer is _______
a. String character
b. A syntax tree
c. A set of RE
d. A set of tokens
18. From the following grammars, which describes the lexical syntax?
a. Lexical Grammar
b. Context-free Grammar
c. Syntactic Grammar
d. Regular Grammar
19. Which of the following is a system program that integrates a program’s individually
compiled modules into a form that can be executed?
a. Interpreter
b. Assembler
c. Compiler
d. Linking Loader
20. Which of the following is a part of a compiler that takes as input a stream of
characters and produces as output a stream of words along with their associated
syntactic categories?
a. Optimizer
b. Scanner
c. Parser
d. None of the mentioned
8
UU – COM-4022
Artificial Intelligence
and Compiler Design
Part 2: Logical questions (20 points)
1. Fill in the values of the four evaluation criteria for each search strategy shown.
o Assume a tree search where b is the finite branching factor;
o d is the depth to the shallowest goal node;
o m is the maximum depth of the search tree;
o l is the depth limit;
o step costs are identical and equal to some positive ε;
o in bidirectional search both directions use breadth-first search.
9
UU – COM-4022
Artificial Intelligence
and Compiler Design
2. For each of the following terms on the left, write in the letter corresponding to the
best answer or the correct definition on the right.
* The first one is done for you as an example.
10
UU – COM-4022
Artificial Intelligence
and Compiler Design
Part 3: Short Answers (20 points)
1. What are the Probabilistic methods (Bayesian) and Certainty Factors (CF)?
2. What is Implementation of Block Structured Language in compiler design?
3. What is Input Buffering in Compiler Design?
4. What is Non-Immediate Left Recursion in compiler design?
5. Describe in your own words Token, Patterns, and Lexemes?
11
UU – COM-4022
Artificial Intelligence
and Compiler Design
Part 4: Lab Tasks (40 points) 1. Write a C program to identify whether a given line is a comment or not.
Hints:
RESOURCE: Turbo C++
PROGRAM LOGIC:
Read the input string.
Check whether the string is starting with ‘/’ and check next character is ‘/’ or’*’.
If condition satisfies print comment.
Else not a comment.
PROCEDURE: Go to debug -> run or press CTRL + F9 to run the program.
INPUT & OUTPUT:
Input:
Enter comment: //hello
Output: It is a comment
Input: Enter comment: hello
Output: It is not a comment
2. Write a C program to recognize strings under 'a*', 'a*b+', 'abb'
Hints:
RESOURCE: Turbo C++ 3.3
PROGRAM LOGIC:
By using transition diagram we verify input of the state.
If the state recognize the given pattern rule.
Then print string is accepted under a*/ a*b+/ abb.
12
UU – COM-4022
Artificial Intelligence
and Compiler Design
Else print string not accepted.
PROCEDURE: Go to debug -> run or press CTRL + F9 to run the program.
INPUT & OUTPUT:
Input : Enter a String: aaaabbbbb
Output: aaaabbbbb is accepted under rule 'a*b+'
Enter a string: cdgs
cdgs is not recognized
3. Write a C program to test whether a given identifier is valid or not.
Hints: RESOURCE: Turbo C++
PROGRAM LOGIC: Read the given input string.
Check the initial character of the string is numerical or any special character except ‘_’
then print it is not a valid identifier.
Otherwise print it as valid identifier if remaining characters of string doesn’t contains any
special characters except ‘_’.
PROCEDURE: Go to debug -> run or press CTRL + F9 to run the program.
INPUT & OUTPUT:
Input: Enter an identifier: first
Output: Valid identifier
Enter an identifier:1aqw
Not a valid identifier
13
UU – COM-4022
Artificial Intelligence
and Compiler Design
4. Write a C program to simulate lexical analyzer for validating operators.
Hints:
RESOURCE: Turbo C++
PROGRAM LOGIC:
Read the given input.
If the given input matches with any operator symbol.
Then display in terms of words of the particular symbol.
Else print not a operator.
PROCEDURE: Go to debug -> run or press CTRL + F9 to run the program.
INPUT & OUTPUT:
Input Enter any operator: *
Output Multiplication
NOTE - You will need to provide screenshots and/or program code of the exercises as proof of
completion of the exercises above