Self Studies

Compiler Design Test 2

Result Self Studies

Compiler Design Test 2
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    1 / -0
    Which of the following statement is true?
    Solution

    Concept:

    Among all the parsers Canonical LR (CLR) parser is most power full than other parsers.

    Increasing order of parser’s power:  LL(1) <  SLR < LALR  < CLR

    Explanation:

    From above order we can say that CLR is the most power full parser, hence option 3 is the correct answer.
  • Question 2
    1 / -0
    Consider the following grammar in which start symbol = {S}, Non Terminal symbol = {A, B, C, D} and Terminal symbol = {a, p, q, r, s, ϵ}. 

    S → A B | p r C | C q 

    A → a S | C

    B → q | ϵ

    C → r | ϵ

    D → B s | ϵ  

    Find the number of terminals in the FIRST(S)?

    Solution

    FIRST(S) = {FIRST(A) ∪ p ∪ FIRST(C)

    FIRST(A) = a ∪ FIRST(C)

    FIRST(C) = {r ∪ ϵ}

    NOW, FIRST(S) = {a ∪ p ∪ r ∪ q ∪ FIRST(B)

    FIRST(B) =   q ∪ ϵ ∪ FIRST(C)

    FIRST(S) = {a ∪ p ∪ r ∪ q ∪ ϵ} 

    the number of terminals in the FIRST(S) is 5.

  • Question 3
    1 / -0
    Input taken by semantic analyzer and output produces by semantic analyzer are
    Solution

    Phases of Compiler

    Input

    Output

    Lexical Analyzer

    Character stream

    Token stream

    Syntax Analyzer

    Token stream

    Syntax tree

    Semantic Analyzer

    Syntax tree

    Syntax tree

    Intermediate Code Generator

    Syntax tree

    Intermediate representation

    Machine-Independent Code Optimizer

    Intermediate representation

    Intermediate representation

    Code Generator

    Intermediate representation

    Target-machine code

    Machine-Dependent Code Optimizer

    Target-machine code

    Target-machine code

  • Question 4
    1 / -0

    Which of the following statements is/are true about the parser?

    A. Leftmost derivation is used for Bottom-up parser.

    B. Rightmost in reverse derivation is used by LL parser.

    Solution

     Parser

     Derivation

     LR parsers or Bottom-up Parsers 

     Rightmost reverse Derivation 

     LL parsers or Top-down Parsers

     Leftmost Derivation

    Therefore, both statements are false. Hence option 4 is correct

  • Question 5
    1 / -0

    Consider the below given augmented grammar:

    A' → A

    A → a B b | num

    B → B c A | A | @

    If C0 = CLOSURE ({[A' → •A]}) then the number of items in the set GOTO (C0, a) is ______
    Solution

    Table: GOTO (C0, a)

     CLOSURE ({[A' → •A]})

    A' → .A

    A → .a B b | num

     

    GOTO (C0, a)

    A → a.B b | num

    B → .B c A

    B → .A

    A → .aB b  

    A → .num

    B → .@

    ∴ number of items in the set GOTO (C0, a) is 6
  • Question 6
    1 / -0

    Consider the following grammar:

    S → aS'

    S' → aS' | ϵ 

    Above grammar is

    I. not left recursive

    II. not ambiguous

    III. LL(1) 

    Which of the following is/are true?

    Solution

    Statement I:

    S → aS'  \\ right recursive 

    S' → aS' | ϵ  \\ right recursive 

    Therefore given grammar is not left recursive

    Statement II:

    Two parse trees cannot be generated for any string in the given grammar and hence it is not ambiguous.

    Statement III:

    A grammar G is LL(1) iff. for all non-terminals A, each distinct pair of productions A → β and A → γ satisfy the condition FIRST(β) \(\cap\) FIRST(γ) = φ.

    A grammar G is LL(1) iff. for each set of productions A→α1 |α2 |···|αn:

    1. FIRST(α1), FIRST(α2), ..., FIRST(αn) are all pairwise disjoint

    2. If αi ⇒ *ε then FIRST(αj) \(\cap\) FOLLOW(A) = φ, ∀1 ≤ j ≤ n, i \(\neq\) j

    Grammar is LL(1):

    NON- TERMINAL

    FIRST

    FOLLOW

    S

    a

    $

    S’

    a, ϵ

    $

     

    Although  FIRST(S') has ϵ, FIRST(S') and FOLLOW(S') doesn't contain any common element. Therefore a cell in parsing table will contain at most one entry in it and hence it is LL(1)

  • Question 7
    1 / -0

    Consider the grammar given below:

    X → Px

    P → RQ | R

    Q → y | w | ε

    R → z | ε

    Let x, y, z, w, and $ be indexed as follows:

    X

    y

    Z

    w

    $

    1

    2

    3

    4

    5

     

    Compute the FOLLOW set of the non-terminal R and write the index values for the symbols in the FOLLOW set in the ascending order. (For example, if the FOLLOW set is {x, y, z, w, $}, then the answer should be 12345)

    Solution

    P → RQ | R

    FOLLOW of R is FIRST of Q

    FIRST of Q is {y, w, ϵ}

    Since epsilon cannot be follow

    FOLLOW of R from is FOLLOW of P

    FOLLOW of P is {x}

    ∴ FOLLOW of R is {x, y, w}

    From table, x = 1, y = 2 and z = 4

    Therefore 124 is the answer.
Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Selfstudy
Selfstudy
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now