Consider the given grammar A → eS | Cr| ξ C → f/p/ξ
S → Abc | ad
Compute FIRST (A)
FIRST (A) = {e, f, p, r, \(\epsilon\) }
This solution explains the process of calculating the FIRST set for a specific non-terminal 'A' using the rules of a given context-free grammar. The FIRST set of a non-terminal contains all the possible terminal symbols that can begin a string derived from that non-terminal, including the empty string (\(\epsilon\)) if the non-terminal can derive it.
The context-free grammar provided is:
In this grammar, 'ξ' represents the empty string (epsilon, denoted as \(\epsilon\)). 'S', 'A', and 'C' are non-terminal symbols, while 'a', 'b', 'c', 'e', 'f', 'p', 'r', and 'd' are terminal symbols.
We need to find the set of all terminals that can start a string derived from 'A'. We examine each production rule for 'A':
The rule states that 'A' can directly produce 'e' followed by 'S'. Since 'e' is a terminal symbol, it is the first possible symbol in a string derived from 'A'.
Therefore, 'e' is added to FIRST(A).
Contribution from this rule: {e}
This rule states that 'A' can produce 'C' followed by 'r'. Here, 'C' is a non-terminal. To find the terminals that 'A' can start with via this rule, we first need to find the FIRST set of C (FIRST(C)).
Let's look at the rules defining 'C':
Combining these, we get: FIRST(C) = {f, p, \(\epsilon\)}.
Now, we use the calculated FIRST(C) for the rule A → Cr:
Contribution from this rule: {f, p, r}
This rule directly shows that 'A' can derive the empty string, \(\epsilon\).
Therefore, \(\epsilon\) is added to FIRST(A).
Contribution from this rule: {\(\epsilon\)}
To get the complete FIRST(A) set, we unite the contributions from all the rules for 'A':
Combining these sets: FIRST(A) = {e} \(\cup\) {f, p, r} \(\cup\) {\(\epsilon\)}
This results in: FIRST(A) = {e, f, p, r, \(\epsilon\)}.
The computed FIRST set for the non-terminal A is {e, f, p, r, \(\epsilon\)}.
| A | S $\rightarrow$ Ab aS$\rightarrow$ aA A$\rightarrow$ a | B | S $\rightarrow$ Ab A $\rightarrow$ Sa A $\rightarrow$ a |
| C | S $\rightarrow$ AS S $\rightarrow$ aA A$\rightarrow$ a | D | S $\rightarrow$ Ab S $\rightarrow$ aA A$\rightarrow$ a |
| E | S $\rightarrow$ Sb A $\rightarrow$ Aa A $\rightarrow$ $\varepsilon$ |
Which of the following grammars is (are)ambiguous ?
(1) S → SS | aSb | bSa |e
(2) S → aSbS | bSaS |e
(3) S → aAB
A → bBb
B → A Ι e
Consider the grammar,
G = S → abScB | e,
B→ bB | b.
What is the language generated by the given grammar ?
Select the sentence which is meaningful and grammatically correct.