GATE 2005 Computer Science and Information Technology (CS) Questions with Solutions

GATE 2005

203 questions

MCQ 2031-mark 203

Questions 141–145 of 203

Q141Parsing1 markMCQ−0.33 if wrong
Consider the context-free grammar
E→E+EE\rightarrow E+E
E→(E∗E)E\rightarrow (E *E)
E→idE\rightarrow \text{id}
where E is the starting symbol, the set of terminals is {id,(,+,),∗}\{id, (,+,),*\}, and the set of nonterminals is {E}. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?

Q142Parsing1 markMCQ−0.33 if wrong
Consider the following expression grammar. The semantic rules for expression calculation are stated next to each grammar production.
E → number          E.val = number.val
  | E ‘+’ E         E(1).val = E(2).val + E(3).val
  | E ‘×’ E         E(1).val = E(2).val × E(3).val

Assume the conflicts of this question are resolved usinf yacc tool and an LALR(1) parser is generated for parsing arithmetic expressions as per the given grammar. Consider an expression 3 x 2 + 1. What precedence and associativity properties does the generated parser realize?

Q143Parsing1 markMCQ−0.33 if wrong
Consider the following expression grammar. The semantic rules for expression calculation are stated next to each grammar production.
E→ numberE.val = number.val
    | E ‘+’ EE(1).val = E(2).val + E(3).val
    | E ‘×’ EE(1).val = E(2).val × E(3).val

The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1) parser generator) for parsing and evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar?

Q144Parsing1 markMCQ−0.33 if wrong
Consider the grammar:

S →\rightarrow (S) | a

Let the number of states in SLR (1), LR(1) and LALR(1) parsers for the grammar be n1, n2 and n3 respectively. The following relationship holds good:

Q145Parsing1 markMCQ−0.33 if wrong
Consider the grammar:

E →\rightarrow E + n | E * n | n

For a sentence n + n * n, the handles in the right-sentential form of the reduction are: