Consider the following grammar: P → xQRS Q → yz |z R → w | ε S → y What is FOLLOW(Q)?

Consider the following grammar: P → xQRS Q → yz |z R → w | ε S → y What is FOLLOW(Q)? Correct Answer {w, y}

Concept:

Follow(X) is the set of terminals that can appear immediately to the right of non-terminal X in some sentential form. Rules for finding the follow (X) are given here as:

1) Follow (S) = {$}, where S is the start symbol.

2) If A → bBC is the production, where b, B and C are grammar symbols, then Follow (B) is first (C).

3) If A → bB is production then follow (B) is follow (A).

4) If A → bBC is production and first(c) contains ε, then follow (B) contains {first (C) - ε} U follow (A).

Explanation:

Follow (Q) = First (RS) = {w, ε} = {w}, First (S) = {w, y}

Diagram:

Related Questions

Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation (SDT) actions, given as pseudo-code: P → D* E* D → int ID {record that ID.lexeme is of type int} D → bool ID { record that ID.lexeme is of type bool} E → E1 + E2 {check that E1.type = E2.type = int; set E.type := int} E → !E1 {check that E1.type = bool; set E.type := bool} E → ID {set E.type := int} With respect to the above grammar; which one of the following choices is correct?