System Programming Compiler
System Programming Compiler
August 2021
Answer to Question No. 1 is compulsory and Answer any two questions from the rest.
2. a) Discuss briefly about the structure of a compiler touching upon all its phases with a neat block diagram.
b) Explain how the following assignment statement would be translated through the different phases of
compilation:
position = initial + rate 7+8 60 ٭
3. a) List out the lexemes and their corresponding tokens for the C-code fragment below :
1
5. a) Disambiguate the following grammer that would generate arithmetic expressions involving operators ‘+’,
‘‒’ (binary), ‘’٭, ‘/’, ‘↑’ and ‘‒’ (unary), denoting addition, subtraction, multiplication, division,
exponentiation and negation respectively:
E -> E + E | E ‒ E | E ٭E | E / E | E ↑ E | ‒ E | (E) | a | b
b) Eliminate the non-immediate left recursion from the grammer below:
S -> Aa | b
A -> Ac | Sd | e
c) By left factoring, eliminate the non-determinism from the grammer below:
S -> aSSbS | aSaSb | abb | b
d) Discuss briefly about the working of a backtracking top-down parser with a suitable example.
4+3+4+4
6. a) Write recursive routines for a recursive-descent parser parsing for the grammer below:
E -> TE′
E′ -> +TE′ | ϵ
T -> (E) | a
b) (i) What is a handle?
(ii) Given the grammer below, find the handles of the right sentential forms of the reduction sequence for
the input string “id + id ٭id $” :
E -> E + E | E ٭E | id
(iii) Step through the sequence of moves a general bottom-up parser would make in parsing the input string
“id + id ٭id $” according to the grammer in (ii). 4+(3+4+4)
7. a) Check with proper justification whether the following grammer is LL(1) or not:
S -> iEtSS′ | a
S′ -> eS | ϵ
E -> b
b) Define operator grammer with an example. Convert the following non-operator grammer into an
equivalent operator grammer :
S -> SAS | a
A -> bSb | b
c) (i) Construct the operator precedence table for the following operatorgrammer for generating arithmetic
expressions involving operators ‘+’ and ‘’٭, denoting addition and multiplication respectively:
E -> E + E | E ٭E | id
(ii) Using the table obtained in (i), show the sequence of moves an operator precedence parser would make
on the input string “id + id ٭id $”. 3+(3+2)+(3+4)
9. a) Discuss briefly about the components and working of an LR parser with a neat diagram.
b) Consider the augmented grammer below:
E′ -> E
E -> E + T | T
T -> T ٭F | F
F -> (E) | id
Find:
(i) CLOSURE ( { [ E′ -> •E ] } )
(ii) GOTO ({ [ E′ -> E• ], [ E -> E• + T ] }, + ) 9+(3x2)
2
10. a) Explain the concept of ‘macro call within macro’ with an example.
b) Discuss briefly about the two pass macro processor algorithm. 5+10
_____________________