CMP 479 Exam 2014-2015
CMP 479 Exam 2014-2015
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)