Q1. Define The Following With Simple Example (Choose Five Only) :: A Grammar That Produces More Than One Parse Tree For Some
Q1. Define The Following With Simple Example (Choose Five Only) :: A Grammar That Produces More Than One Parse Tree For Some
(5) Conflicts
"Conficts" occur when an ambiguity in the grammar creates a situation where
the parser does not know which step to perform at a given point during parsing. There
are two kinds of conflicts that occur
1. shift-reduce: a shift reduce conflict occurs when the grammar indicates that
different successful parses might occur with either a shift or a reduce at a given point
during parsing.
The vast majority of situations where this conflict occurs can be correctly resolved by
shifting.
2- reduce-reduce : a reduce-reduce conflict occurs when the parser has two or more
handles at the same time on the top of the stack. Whatever choice the parser makes is
just as likely to be wrong as not. In this case it is usually best to rewrite the grammar
to eliminate the conflict, possibly by factoring.
(10 marks)
Q.2) briefly answer the following (choose three only)
Code Motion
An important modification that decreases the amount of code in a
loop is code motion. This transformation takes an expression that yields
the same result independent of the number of times a loop is executed and
places the expression before the loop.
Ex1: While ( I <= limit-2)
Sol: t = limit-2
While (I <= t )
Induction Variable
Ex: X = 2 * y + 2 * h + 4
Sol: X = 2 * (y + h) +4
Note: use the algebra method to optimize the mathematical expression.
Reduction in strength
Reduction in strength, which replaces an expensive operation by a
cheaper one, such as a multiplication by an addition.
Ex: t4 = 4*j - 4
D) List the four error routines in the bottom-up parsing table, and what is the suitable
solution for each type.
(10 marks)
Q.3) Consider the following grammar G.
3. After finding first and follow we will find that in first nonterminal that contain
empty there is not find the same terminal in the follow of that nonterminal so the
grammar is LL(1).
(10 marks)
Q.4) Consider the following grammar:
(10 marks)
Q.5) Given the following grammar:
The terminals are = {a,b,0,1} , and the nonterminals are={S,A,B}. Parse the sentence
"aa1bbbb" using SLR parsing method.
(10 marks)
Q.6) A: Write the triple and quadruple form for the following statement:
1. Triple
op Arg 1 Arg2
(0) + c d
(1) =[ ] A i
(2) * 0 1
(3) / Y Z
(4) + B 2
(5) - 4 3
(6) [ ]= A J
= 6 5
2. Quadruple
(10 marks)