First of all, we need to clarify the extended form of grammar G. This grammar has two productions, which can be expressed as G': S'→aA'
A'→Abc'|c"
Where a, b, and c represent respectively A single character, single quotes indicate that the character is a non-terminal symbol
Next, we proceed with the following steps:
(1) Expand the grammar and construct a project based on LR(0). A DFA that can identify all its live prefixes.
For grammar G', we can obtain the LR(0) item set specification family through extension. First, we need to construct an LR(0) automaton. The following is the construction process:
Define the state set Q, including q0, q1, q2.
Define the input symbol set Σ, including a, b, c, #, where # means. Empty character.
Define the item set I, including {(q0, a), (q1, b), (q2, c)}.
Define the closure of the itemset I. FOLLOW(A), where A is a non-terminal symbol. FOLLOW(A) includes all symbols that can follow A.
Definition of the closure FIRST(A) of the item set I, where A is a non-terminal symbol. symbol. FIRST(A) includes all symbols that can appear before A.
Definition of the closure GO(q, A) of the item set I, where q is the state and A is the non-terminal symbol GO(. q, A) includes all new states that can be transferred to by q and A.
Define the closure GOTO(I, A) of the itemset I, where I is the itemset and A is a non-terminal symbol. GOTO(I, A) includes all new itemsets that can be transferred to by executing the A production.
A closure NEXT(I) that defines itemset I, where I is the itemset NEXT(I). Includes all new itemsets that can be transferred to by executing all productions in I.
Define the closure generalization condition CIC(I) of the itemset I, where I is the itemset CIC(I). Includes all conditions that can be completed by executing all productions in I without producing a new itemset.
The closure condition FINISH(I) that defines the itemset I, where I is the itemset FINISH(. I) includes all conditions that can be executed by executing all the productions in I and there are no remaining itemsets.
According to the above construction process, we can get all activities based on LR(0) items. DFA of prefix.
(2) Is this grammar an LR(0) grammar?
First of all, according to the extended grammar G ', we can get the LR(0) itemset specification family. In the LR(0) item, each production corresponds to an itemset. By definition, the itemset specification family is a set of LR(0) itemset families. , which satisfies the following condition: for each itemset I, if there is a production A→α and α is a prefix in I, then there is an itemset J contained in I such that α is a suffix of J. Therefore, grammar G' is an LR(0) grammar.
Secondly, according to the extended grammar G', we can get the calculation results of the FIRST set and the FOLLOW set. According to the definition of SLR(1) grammar, a grammar is an SLR(1) grammar if and only if for every non-terminal symbol A and every production A → α, there exists a state i such that α is FIRST[i] substring. However, for the productions A→Abc and A→c in grammar G', there are multiple states satisfying the condition FIRST[i] containing the prefix of α. Therefore, grammar G' is not an SLR(1) grammar.