0% found this document useful (0 votes)
17 views2 pages

CMP 479 Exam 2014-2015

This document contains 6 questions for a compiler construction exam. The questions cover topics like language translators, lexical analysis, parsing, ambiguity, left recursion, LR parsing and postfix notation.

Uploaded by

geehustle06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

CMP 479 Exam 2014-2015

This document contains 6 questions for a compiler construction exam. The questions cover topics like language translators, lexical analysis, parsing, ambiguity, left recursion, LR parsing and postfix notation.

Uploaded by

geehustle06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

REDEEMER’S UNIVERSITY (RUN)

Department of Computer Science


1ST SEMESTER EXAMINATION 2014/2015 SESSION
COURSE CODE: CMP 479
COURSE TITLE: COMPILER CONSTRUCTION
Course Unit: 3 Time Allowed: 3 Hours
Instruction: Answer any four questions

Question 1
a. What are language translators?
b. Compare the following: assembler, interpreter and a compiler
c. What qualities are important in a compiler?
d. Describe any four software tools that can manipulate source programs
e. Write short notes on Symbol Table Management
f. Optimize the code below
temp1 := inttoreal(60)
temp2 := id3 * temp1
temp3 := id2 + temp2
id1 := temp3

Question 2
a. Briefly describe any three general approaches used for the implementation of a
lexical analyzer.
b. Highlight any three functions/roles of
(i). the Scanner (ii). the Parser
c. Using Lex convention, write regular definitions for identifying
(i). an identifier in Java programming language
(ii) a date (giving one example of such date)
d. Construct a transition diagram for identifying:
(i) white space and (ii) unsigned numbers

Question 3
a. Discuss the problems of operator precedence parsers
b. Consider the operator grammar G3B with productions defined as follows:
E → E+E |E-E |E*E |E/E |id
Construct an operator precedence relation table for grammar G3B
c. Perform the left factoring process on the grammar G3C below:
Stat → if Cond then Stat | if Cond then Stat else Stat | a
Cond → b
d. Discuss any three error recovery strategy for syntax errors

Question 4
a. What is a parser?
b. Define the following grammatical terms as used in the compilation process:
i. A Handle
ii. Start symbol
iii. Terminals
iv. Nonterminals
v. Productions
c. Discuss the difficulties of top-down parsers
d. Given grammar G4D with productions listed as follows:
stat → if expr then stat
| if expr then stat else stat
| other-stat
and the sentence: if Expr1 then if Expr2 then Stat1 else Stat2.
Prove that grammar G4D is ambiguous

Question 5
a. What is a recognizer?
b. Consider grammar G5B for arithmetic expressions shown below:
E → E - E|E / E| id
Show that the sentence a - b / c has two distinct leftmost derivations.
c. When is a grammar said to be left-recursive?
d. Consider the grammar G5D below:
A→A-B
A→B
B→B/C
B→C
C → (A)
C→d
(i) Is grammar G5D left recursive?
(ii) If yes, eliminate the left recursion from the grammar
e. Design a NFA to accept the language (aa*|bb*)*

Question 6
Consider the grammar G6 with productions listed as follows:
S→L=R
S→R
L → *R
L → id
R→L
a. Compute the FIRST and FOLLOW set for grammar G6
b. Construct a canonical collection of sets of LR(0) Items for grammar G6
c. Write the postfix notation for the following expressions:
(i) a*(b+c)
(ii) (a+b) * (c+d)

You might also like