Compiler Question Solution

3
1.Explain stack implementation of shift reduce parsing. 5 id1 + id2 * id3$ Solution:- Shift reduce parser (2 Marks) Parsing table (3 Marks) 2.Explain the non-recursive implementation of predictive parsers. 5 Solution:- What is predictive parser?(1 Marks) Benefits of non recursive implementation (1 Marks) Table of actions (3 marks) 3.Generate target code for the source language statement 5 (a-b) + (a-c) + (a-c) Solution:- Three address code representation (2 Marks) Representation with instructions(3 Marks) 4.Explain design goals for garbage collector. 5 Solution:- What is garbage (1 Marks) Fragmentation (1 Marks) Different methods of garbage collection (3 Marks)

description

compiler design

Transcript of Compiler Question Solution

  • 1.Explain stack implementation of shi ft reduce parsing. 5

    id1 + id2 * id3$ Solution:- Shi ft reduce parser (2 Marks) Parsing table (3 Marks)

    2.Explain the non-recursive implementation of predictive parsers. 5 Solution:-

    What is predictive parser?(1 Marks) Benefi ts of non recursive implementation (1 Marks) Table of actions (3 marks)

    3.Generate target code for the source language statement 5 (a-b) + (a-c) + (a-c)

    Solution:- Three address code representation (2 Marks) Representation with instructions(3 Marks)

    4.Explain design goals for garbage collector. 5 Solution:- What is garbage (1 Marks) Fragmentation (1 Marks) Di fferent methods of garbage col lection (3 Marks)

  • 5.Consider the following grammar G where E is the start symbol -

    E -> E + T | T T -> T * F | F F -> ( E ) | id

    (a) Is G un-ambiguous? Why? 5

    (b) why is G not sui table for recursive descent parsing?

    Rewri te G as G' to make i t sui table. 5

    (c) Compute FIRST and FOLLOW for each non -terminal of G'. 5

    (d) Construct the predictive parsing table for the grammar G'. 5

    Solution :-

    a) Ambiguity in grammar(2 Marks)

    reason with example(3 marks)

    b) Recursive decent parsing(2 marks)

    rewri tten grammar (3 Marks)

    c) First set (2.5 marks)

    Fol low set (2.5 Marks)

    d) parser action table (5 Marks)

    6.Generate the intermediate code for the statement:

    Sum: = A[I, j] + B[I, j]. Construct DAG and simpl i fy the code. 10

    Solution:- Three address code representation (3 marks) DAG (3 marks) Optimized code (4 marks)

    7.For the SDD shown below

    Construct the annotated parse for 3*5+4n. 10

  • Solution :- Parse table with selected rule for parsing every element(3 Marks) Conversion of str ing into syntax tree (3 Marks) Annotation parse tree (4 marks)