5
VIDHYADEEP INSTITUTE OF ENGINEERING AND TECHNOLOGY Vidhyadeep Campus, Anita (Kim), Ta. Olpad, Dist. Surat Subject Name: Compiler Design Subject Code: 2170701 Sem: 7 th (2018-19) Assignment-1 Q.1 How top down and bottom up parser will parse the string ‘bbd’ using grammar A-> bA | d Show all steps clearly. Q.2 What is bottom-up parsing? Discuss Shift Reduce parsing technique in brief. What is a handle&handle pruning? Q.3 Eliminate left recursion from the following grammar and rewrite the Grammar. S -> Aa | b A -> Ac | Sd | Є Q.4 Perform the Left factoring of following Grammar A->ad | a | ab | abc | b Q.5 Construct predictive parsing table for following. S -> A A -> aB | Ad B -> bBC | f C -> g Q.6 Construct predictive parsers for the following grammar. E → E+T|T T → T*F|F F → (E)|id Q.7 Construct Recursive Descend Parser for: S->ABC A->0A1 | ˄ B->1B | ˄ C->1C0 | ˄ Q.8 Find out FIRST & FOLLOW set for all the Non-Terminals S→ AcB | cbB | Ba A→ da | BC B→ g | Є C→ h | Є Q.9 Test whether the following grammar is LL (1) or not. Construct predictive parsing table for it. S→ 1AB | Є A→ 1AC | 0C B→ 0S C→ 1 Q.10 Is the following grammar suitable for LL(1) parsing? If not make it suitable for LL(1) parsing. Compute FIRST and FOLLOW sets. Generate the parsing table. S→AB A→Ca | Є

Assignment-1 · Assignment-1 Q.1 How top down and bottom up parser will parse the string ‘bbd’ using grammar A-> bA | d Show all steps clearly. Q.2 What is bottom-up parsing?

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

  • VIDHYADEEP INSTITUTE OF ENGINEERING AND TECHNOLOGY

    Vidhyadeep Campus, Anita (Kim), Ta. Olpad, Dist. Surat

    Subject Name: Compiler Design Subject Code: 2170701 Sem: 7th(2018-19)

    Assignment-1

    Q.1 How top down and bottom up parser will parse the string ‘bbd’ using grammar

    A-> bA | d

    Show all steps clearly.

    Q.2 What is bottom-up parsing? Discuss Shift Reduce parsing technique in brief. What is

    a handle&handle pruning?

    Q.3 Eliminate left recursion from the following grammar and rewrite the Grammar.

    S -> Aa | b

    A -> Ac | Sd | Є

    Q.4 Perform the Left factoring of following Grammar

    A->ad | a | ab | abc | b

    Q.5 Construct predictive parsing table for following.

    S -> A

    A -> aB | Ad

    B -> bBC | f

    C -> g

    Q.6 Construct predictive parsers for the following grammar.

    E → E+T|T

    T → T*F|F

    F → (E)|id

    Q.7 Construct Recursive Descend Parser for:

    S->ABC

    A->0A1 | ˄

    B->1B | ˄

    C->1C0 | ˄

    Q.8 Find out FIRST & FOLLOW set for all the Non-Terminals

    S→ AcB | cbB | Ba

    A→ da | BC

    B→ g | Є

    C→ h | Є

    Q.9 Test whether the following grammar is LL (1) or not. Construct predictive parsing

    table for it.

    S→ 1AB | Є

    A→ 1AC | 0C

    B→ 0S

    C→ 1

    Q.10 Is the following grammar suitable for LL(1) parsing? If not make it suitable for LL(1)

    parsing. Compute FIRST and FOLLOW sets. Generate the parsing table.

    S→AB

    A→Ca | Є

  • VIDHYADEEP INSTITUTE OF ENGINEERING AND TECHNOLOGY

    Vidhyadeep Campus, Anita (Kim), Ta. Olpad, Dist. Surat

    B→BaAC | c

    C→b | Є

    Q.11 Implement the following grammar using Table Driven parser and check whether it is

    LL(1) or not.

    S -> aBDh

    B -> cC

    C -> bC / ^

    D -> EF

    E -> g / ^

    F-> f / ^

    Q.12 For the following grammar

    D ->T L ;

    L ->L , id | id

    T ->int | float

    1)Remove left recursion (if required)

    2)Find first and follow for each non terminal for Resultant grammar

    3)Construct LL(1) parsing table

    4)Parse the following string (show stack actions clearly) and draw parse tree for the

    input:

    int id, id;

    Q.13 Draw parsing table for Table Driven Parser for the given grammar. Is the grammar

    LL(1)?

    A->AaB | x

    B->BCb | Cy

    C->Cc | ˄

    Q.14 Implement the following grammar using Recursive Descent Parser.

    S -> Aa | bAc | bBa

    A -> d

    B -> d

    Q.15 Develop a predictive parser for the following grammar.

    S’->S

    S->aA|b|cB|d

    A->aA|b

    B->cB|d

    Q.16 Construct LL(1) parsing table for the following Grammar:

    S -> ( L ) | a

    L -> L , S | S

    Subject Coordinator H.O.D.

  • VIDHYADEEP INSTITUTE OF ENGINEERING AND TECHNOLOGY

    Vidhyadeep Campus, Anita (Kim), Ta. Olpad, Dist. Surat

    Subject Name: Compiler Design Subject Code: 2170701 Sem: 7th(2018-19)

    Assignment-2

    Q.1 Consider the following grammar

    E → E+T | T

    T → TF | F

    F → F* |a |b

    1) Construct the SLR parsing table for this grammar.

    2) Construct the LALR parsing table.

    Q.2 Show that the following grammer

    S->Aa | bAc | dc | bda

    A->d

    is LALR(1) but not SLR(1).

    Q.3 Show that the following grammer

    S->Aa | bAc | Bc | bBa

    A->d

    B->d

    is LR(1) but not LALR(1).

    Q.4 Generate the SLR parsing table for the following Grammar

    S->Aa | bAc | bBa

    A->d

    B->d

    Q.5 Write SLR parsing table for:

    S->T

    T->CC

    C->cC

    C->d

    Q.6 Construct the canonical parsing table for the following Grammar

    S’->S

    S->CC

    C-> cC | d

    Q.7 Explain operator precedence parser by giving example for constructing a precedence

    graph and table.

    Q.8 Write down steps to set precedence relationship for Operator Precedence Grammar.

    Design precedence table for:

    E->E+ T | T

    T->T * F | F

    F->a

    Q.9 What is Intermediate form of the code? What are the advantages of it? Whatare

    generally used intermediate forms? Write N-Tuple notation for:

  • VIDHYADEEP INSTITUTE OF ENGINEERING AND TECHNOLOGY

    Vidhyadeep Campus, Anita (Kim), Ta. Olpad, Dist. Surat

    (a+b)*(c+d)-(a+b+c)

    Q.10 What is the difference between parse tree and syntax tree? Draw the parse tree for

    following expression: a= a + a * b + a * b * c – a / b + a * b andwrite three address

    code for it.

    Q.11 Draw syntax tree and DAG for following statement. Write three address codes from

    both.

    a = (a + b * c) ^ (b * c) + b * c

    Q.12 Convert the following statement into triple, indirect triple and quadruple forms.

    A= (B+C) $ E + (B+C) *F

    Q.13 Translate the arithmetic expression a*-(b+c) into

    1. Syntax tree

    2. Postfix notation

    3. Three address code

    Q. 14 What is inherited attribute? Write syntax directed definition with inheritedattributes

    for type declaration for list of identifiers. Show annotated parse treefor the sentence.

    real id1,id2,id3.

    Q.15 Show syntax directed definition for simple desk calculator. Also show annotated parse

    tree for 3*5+4n, where n indicates newline.

    Q.16 Construct a Syntax-Directed Translation scheme that translates arithmetic expressions

    from infix into postfix notation. Show the application of your scheme to the string

    3*4+5*2.

    Subject Coordinator H.O.D.

  • VIDHYADEEP INSTITUTE OF ENGINEERING AND TECHNOLOGY

    Vidhyadeep Campus, Anita (Kim), Ta. Olpad, Dist. Surat

    Subject Name: Compiler Design Subject Code: 2170701 Sem: 7th(2018-19)

    Assignment-3

    1. Write a note on peephole optimization.

    2. Discuss various code optimization techniques.

    3. Write the various issues in the design of code generators.

    4. Write an algorithm for global common sub expression elimination.

    5. Explain the roles of linker, loader and preprocessor.

    6. Write down the algorithm for partitioning of basic blocks.

    7. Discuss the factors affecting the target code generation.

    8. Explain Principal Source of code optimization

    9. Explain Compile time Evaluation

    10. Explain Register Allocation and Assignment in Detail

    Subject Coordinator H.O.D.