1.
Construct LL(1) parsing table for the following grammar: Program → begin d Semi X end X → d semi X / s Y Y → semi s Y / λ begindsemiends$Program1 X 2 3 Y 45 What will be the entry for 1:
Correct Answer
B. Program → begin d Semi X end
2.
Construct LL(1) parsing table for the following grammar: Program → begin d Semi X end X → d semi X / s Y Y → semi s Y / λ begindsemiends$Program1 X 2 3 Y 45 What will be the entry for 2:
Correct Answer
C. X → d semi X
Explanation
The entry for 2 in the LL(1) parsing table will be X → d semi X. This is because when the parser sees a non-terminal X followed by the terminal "d", it knows that it should use the production X → d semi X to expand X.
3.
Construct LL(1) parsing table for the following grammar: Program → begin d Semi X end X → d semi X / s Y Y → semi s Y / λ begindsemiends$Program1 X 2 3 Y 45 What will be the entry for 3:
Correct Answer
B. X → s Y
4.
Construct LL(1) parsing table for the following grammar: Program → begin d Semi X end X → d semi X / s Y Y → semi s Y / λ begindsemiends$Program1 X 2 3 Y 45 What will be the entry for 4:
Correct Answer
D. Y → semi s Y
5.
Construct LL(1) parsing table for the following grammar: Program → begin d Semi X end X → d semi X / s Y Y → semi s Y / λ begindsemiends$Program1 X 2 3 Y 45 What will be the entry for 5:
Correct Answer
C. Y → λ
Explanation
The entry for 5 in the LL(1) parsing table will be Y → λ. This is because when the parser sees a "semi" token in the input, it can choose to expand Y → λ, which represents an empty production. This allows the parser to skip over the "semi" token and continue parsing the rest of the input.
6.
Consider the following grammar: E → E + n / E * n / nfor the sentence n+n*n, the handles in the bottom-up parsing will be:
Correct Answer
D. N, E+n and E*n
Explanation
The given grammar is a right-recursive grammar, which means that the rightmost non-terminal in the production rule is expanded first. In the given sentence "n+n*n", the handles are the substrings that match the right side of a production rule and can be reduced to the left side of that rule.
Starting from the leftmost non-terminal, we can see that the handle "n" matches the right side of the production rule E -> n. This handle can be reduced to E.
Next, the handle "E+n" matches the right side of the production rule E -> E + n. This handle can be reduced to E.
Finally, the handle "E*n" matches the right side of the production rule E -> E * n. This handle can also be reduced to E.
Therefore, the handles in the bottom-up parsing of the given sentence are n, E+n, and E*n.
7.
Consider the following two statementsa) Every SLR(1) grammar is also LR(0) grammar.b) Every LL(1) grammar is also LL(2) grammar.Which of the following option is correct?
Correct Answer
B. Only b is true
8.
Consider the following grammar:S → CCC →cC / dThe above grammar is
Correct Answer
A. LL(1)
Explanation
The given grammar is LL(1) because it is a left-to-right, leftmost derivation with one lookahead symbol. In LL(1) parsing, the parser scans the input from left to right, and at each step, it uses a single lookahead symbol to decide which production rule to apply. In this grammar, the non-terminal S can only derive to CCC or cC, and there is no ambiguity or conflict in the productions. Therefore, the grammar is LL(1).
9.
Consider SLR(1) and LR(0) table for any given CFG. Which one of the following is false?
Correct Answer
B. Goto of both the tables may be different
Explanation
The Goto entries in the SLR(1) and LR(0) tables may be different. The Goto entries in the SLR(1) table represent the next state to transition to when a non-terminal symbol is encountered, while the Goto entries in the LR(0) table represent the next state to transition to when a production rule is completed. Since the SLR(1) and LR(0) parsing methods have different lookahead sets, it is possible for the Goto entries to differ between the two tables.
10.
If the parse tree of a word w generated by a Chomsky normal form grammar has no path of length greater than i, then the word w is of length:
Correct Answer
B. No greater than 2 ^ i
Explanation
If the parse tree of a word w generated by a Chomsky normal form grammar has no path of length greater than i, then the word w is of length no greater than 2 ^ i. This is because the Chomsky normal form grammar restricts the length of the paths in the parse tree. Each rule in the grammar either replaces a non-terminal symbol with two non-terminal symbols or with a terminal symbol. Therefore, at each step, the number of symbols in the word doubles. So, if there is no path of length greater than i, then the word can have at most 2 ^ i symbols.