Questions & Answers of Parsing

Question No. 43

Consider the following grammar:
stmt $\style{font-family:'Times New Roman'}\rightarrow$ if expr then expr else expr; stmt | 0
expr $\style{font-family:'Times New Roman'}\rightarrow$ term relop term | term
term $\style{font-family:'Times New Roman'}\rightarrow$ id |number 
id $\style{font-family:'Times New Roman'}\rightarrow$ a | b | c
number $\style{font-family:'Times New Roman'}\rightarrow$ [0-9]
 

where relop is a rational operator (e.g.,<,>,...), O refers to the empty statement, and if, then, else are terminals.

Consider a preogram P following the above grammar containing ten if terminals. The number of control flow paths in P is ________. For example, the program

if e1 then e2 else e3

has 2 control flow paths, $\style{font-family:'Courier New'}{\begin{array}{l}{\mathrm e}_1\;\rightarrow\;{\mathrm e}_2\;\mathrm{and}\;{\mathrm e}_1\;\rightarrow\;{\mathrm e}_3\\\;\end{array}}$.

Question No. 106

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

I. Canonical LR is more powerful than SLR

II. SLR is more powerfull than LALR.

III. SLR is more powerful than Canonical LR.

Question No. 18

Which one of the following is TRUE at any valid state in shift – reduce parsing?

Question No. 215

Among simple LR (SLR), canonical LR, and look – ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most powerful, in that order?

Question No. 265

Consider the following grammar G
SF | H
Fp | c
Hd | c

Where S, F, and H are non – terminal symbols, p, d, and c are terminal symbols. Which of the following statements (s) is/are correct?

S1. LL(1) can parse all strings that are generated using grammar G

S2. LR(1) can parse all strings that are generated using grammar G

Question No. 44

A canonical set of items is given below

S → L. > R
Q → R.

On input symbol < the set has

Question No. 127

Consider the grammar defined by the following production rules, with two operators * and +

S → T ∗ P
T → U | T ∗ U
P → Q + P | Q
Q → Id
U → Id

Which one of the following is TRUE?

Question No. 9

What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon- and unit-production (i.e., of type Aϵ and Aa) to parse a string with n tokens?

Question No. 40

Consider the following two sets of LR(1) items of an LR(1) grammar.

X → c.X, c/d
X → .cX, c/d
X → .d, c/d
X → c.X, $
X →.cX, $
X →.d, $

Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are FALSE?
1. Cannot be merged since look aheads are different.
2. Can be merged but will result in S-R conflict.
3. Can be merged but will result in R-R conflict.
4. Cannot be merged since goto on c will lead to two different sets.

Question No. 52

For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. ε is the empty string, $\$$ indicates end of input, and, | separates alternate right hand sides of productions.

S a A b B | b A a B | ε
A S
B S

  a b $
S E1 E2 S→ε
A A→S A→S error
B B→S B→S E3

The FIRST and FOLLOW sets for the non-terminals A and B are

Question No. 53

For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. ε is the empty string, $\$$ indicates end of input, and, | separates alternate right hand sides of productions.

S a A b B | b A a B | ε
A S
B S

  a b $
S E1 E2 S→ε
A A→S A→S error
B B→S B→S E3

The appropriate entries for E1, E2, and E3 are

Question No. 27

Consider two binary operators ‘↑’ and '↓ ’ with the precedence of operator ↓ being lower than that of the operator ↑ ; . Operator ↑ is right associative while operator↓ is left associative. Which one of the following represents the parse tree for expression (7↓3↑4↑3↓2)?

Question No. 38

The grammar SaSa|bS|c is

Question No. 11

Which of the following describes a handle (as applicable to LR-parsing) appropriately?

Question No. 55

An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if

Question No. 18

Which one of the following is a top-down parser?

Question No. 52

Consider the grammar with non-terminals N = {S,C,S1}, terminals T = {a, b, i, t, e}, with S as the start symbol, and the following set of rules:

S iCtSS1 | a
S1 eS | ε
C b

The grammar is NOT LL(1) because:

Question No. 53

Consider the following two statements:

P: Every regular grammar is LL(1)
Q: Every regular set has a LR(1) grammar

Which of the following is TRUE?

Question No. 78

Consider the CFG with {S, A, B} as the non-term , {a, b} as the terminal alphabet, S as the start symbol and the following set of production rules:  

SaB SbA
Bb Aa
BbS AaS
BaBB AbAA

Which of the following strings is generated by the grammar?

Question No. 79

Consider the CFG with {S, A, B} as the non-term , {a, b} as the terminal alphabet, S as the start symbol and the following set of production rules:  

SaB SbA
Bb Aa
BbS AaS
BaBB AbAA

For the correct answer strings to Q.78, how many derivation trees are there?