Self Studies

Compiler Design Test 3

Result Self Studies

Compiler Design Test 3
  • 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

    Consider the following grammar:

    S → XYZ

    Y.val  = X.val

    Y.val = S.val

    Y.val = Z.val

    Above grammar is

    Solution

    Synthesized attributes:

    A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children.

    S-attributed SDT

    If an SDT uses only synthesized attributes, it is called as S-attributed SDT.

    Y.val = S.val  \\ this violates S-attributed grammar

    Inherited attributes:

    An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute. The attribute can take value either from its parent or from its siblings.

    L-attributed SDT

    If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT.

    Therefore every S-attributed definition is L-attributed but vice versa is not true.

    Explanation:

    Y.val = Z.val   \\this violates L-attributed grammar rule

  • Question 2
    1 / -0
    Which of the following statement is false?
    Solution

    1. True: Synthesized attributes are computed from the values of the attributes of the children nodes. They can be evaluated by a post-order traversal.

    2. True: Inherited attributes of the children can depend on both left and right siblings. Inherited attributes that do not depend from right children can be evaluated by a classical pre-order traversal.

    3. True: A Dependency Graph shows the inter-dependencies among the attributes of the various nodes of a parse-tree.

  • Question 3
    1 / -0

    Consider the grammar with the following translation rules and X as the start symbol.

    X -> X1* Y      {X.value = X1.value * Y.value}

    X -> Y              {X.value = Y.value}

    Y -> Y1- Z       {Y.value = Y1.value - Z.value}

    Y -> Z              {Y.value = Z.value}

    Z -> digit          {Z.value = digit.value}

    What is the value for the root of the parse tree for the expression: 54 – 5 * 1 * 7 – 4?
    Solution

    In above grammar – has higher precedence order than *.

    Hence, - will be evaluated first.

    (54 – 5) * 1 * (7 – 4)

    49 * 1 * 3

    147
  • Question 4
    1 / -0

    Which of the following statement is/are true?

    I. Every L-attributed definition is S-attributed

    II. Every S-attributed definition is L-attributed

    III. Both L-attributed and S-attributed can be used interchangeably

    Solution

    Synthesized attributes:

    A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children.

    S-attributed SDT

    If an SDT uses only synthesized attributes, it is called as S-attributed SDT.

    Inherited attributes:

    An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute. The attribute can take value either from its parent or from its siblings.

    L-attributed SDT

    If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT.

    Therefore every S-attributed definition is L-attributed but vice versa is not true.

  • Question 5
    1 / -0

    Consider the following grammar:
    S → pAS | r
    A → q

    Find the number of reduction steps taken by a bottom-up parser while accepting the string "pqpqpqpqr"?

    Solution

    Concept:

    The class of bottom-up parser follow rightmost derivation in the reverse order.

    Explanation:

    S → pAS                (S → pAS)

    S → pApAS            (S → pAS)

    S → pApApAS        (S → pAS)

    S → pApApApAS    (S → pAS)

    S → pApApApAr     (S → r)

    S → pApApApqr      (A → q)

    S → pApApqpqr       (A → q)

    S → pApqpqpqr        (A → q)

    S → pqpqpqpqr        (A → q)

    Therefore, the number of reduction steps taken by a bottom-up parser while accepting the string "pqpqpqpqr" is 9.

  • Question 6
    1 / -0

    Le the two productions be P → CD and P → AB. Consider the following rules.

    Rule 1: P.i = C.i + D.i and C.i = D.i - 1

    Rule 2: A.i = P.i * 2 and  B.i = A.i + P.i

    Each of the five non-terminals P, A, B, C, and D has two attributes: s is a synthesized attribute, and i is an inherited attribute. 

    Which one of the following is true?
    Solution

    Concept:

    A rule is said to be L- attributed if it used both synthesized and inherited attributes. But, in the inherited attribute, we can get attribute values from the parent or from the left siblings, but not the right sibling.

    Rule 1 is not L- attributed.

    Rule 1: P.i = C.i + D.i and C.i = D.i - 1

    Explanation:

    P.i = C.i + D.i      ...{This is synthesized attribute as Parent P is taking values from children C and D}

    C.i = D.i - 1    ...{Child C is taking value from right sibling D}

    Therefore, this violates the conditions of L- attributed definitions.

    Rule 2 is L- attributed

    Rule 2: A.i = P.i * 2 and  B.i = A.i + P.i

    A.i = P.i * 2      ...{This is inherited attributes as Child P is taking values from its parent P}

    B.i = A.i + P.i  ...{This is inherited attributes  child B is taking attribute value from parent P and left sibling Y}

  • Question 7
    1 / -0

    Consider the below-given Syntax Directed Translation Scheme

    B → aBA          print(“^”);

    B → a               print(“$”);

    A → b              print(“#”);

    What is the output printed by a bottom-up parser, for the input aaaabbb?

    Solution

    Concept:

     Parser

     Derivation

     LR parsers or Bottom-up Parsers 

     Rightmost reverse Derivation 

     LL parsers or Top-down Parsers

     Leftmost Derivation

    Explanation:

    B → aBA      print(“^”);

    B → aBb      print(“#”);

    B → aaBAb   print(“^”);

    B → aaBbb   print(“#”);

    B → aaaBAbb   print(“^”);

    B → aaaBbbb print(“#”); 

    B → aaaaBAbb print(“^”);

    B → aaaaBbbb print(“#”);

    B → aaaaabbb  print(“$”);

    Output: $#^#^#^#^

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