Professional Documents
Culture Documents
A → Aa | b
B → Dd | e
C → Bf | g
D → Df | Aa | Bg
Q-2 Write down the three-address code for following source code:
Do { i = i + 1;
Y = (c + d) * (a + b - c);
Z = Y * Y; }
while (X < 100 || X > 200 && X! = Y)
Q-3 (a) Q-1 Consider the following grammar with terminals class, id , public, final,
extends, implements, and “,” -:
(a) Calculate First and Follow sets for the non-terminals in above grammar
1|Page
Q-3 (b) Fill LL(1) Parsing table with Panic Mode (Mentioned the rule number in the parsing
table)
2|Page
Q-4 Write down SDT to compute type and width of array.
Hint: You have to calculate the first index (row Index) to generate Type Expression and size
calculation of array
Q-5 Consider a very simple query engine (software) that executes a simple SELECT
statement. The engine reads required data from files, and displays it to the screen. It does
so by translating given SELECT statement into low-level API (function) calls.
Following is an example:
The engine translates the above statement into the following API calls:
file = open("student")
data = file.read(["name", "address", "phone"])
display(data)
Assume the SELECT statement does not have any other clause such as WHERE or ORDER BY,
and assume the FROM clause can have only a single parameter (table name). The "*" is not
allowed. Now answer the following three questions.
5-1
List down all the tokens for the SELECT statement. Give regular (RE) definitions for any
complex tokens. Note that the language is not case sensitive: SELECT = select for example.
5-2
Give a left-recursive CFG for the SELECT statement. Of course the statement can have any table
name, any column names, and any number of columns.
5-3
Give a left-recursive translation scheme to translate the SELECT statement into the API calls.
3|Page
Q-6 Write down the SDT that translate the Arithmetic Expression to the Three Address
Code with line number as mentioned in the below example.
(Use L-Attributed Grammar and Not Use Global Variable)
Input Output
Value = X * Y +10 (1) T1 = X * Y
(2) T2 = T1 + 10
(3) Value = T2
4|Page