Compiling principle structure framework 5 bottom-up syntax analysis
Chapter 5 bottom-up syntax analysis
Key points: basic idea of bottom-up analysis, basic idea of operator priority analysis, and simple operator priority analysis. The basic construction idea of LR analyzer, LR analysis algorithm, the regular active prefix of Sentence Pattern and Its identification device-DFA, LR (0) analysis table construction, SLR (1) analysis table construction, LR (1) structure of the analysis table.
Difficulty: Determine FIRSTOP and LASTOP, determine operator precedence, construct operator precedence analysis table, and define the prime phrase and leftmost prime phrase. Regular sentence pattern live prefix, LR (0) project set closure and project set standard family, their relationship with handle identification, relationship between active prefix and handle, LR (1) project set closure and project set standard family.
5.1 core issues of bottom-up syntax analysis:
N search for the current reduction object in the sentence structure-"handle" for reduction. You can use different methods to find the handle to obtain different analysis methods.
5.2 calculate FIRSTOP:
If the formula B-> B... or B-> Cb is generated, then bε FIRSTOP (B )\
If there is formula A-> B, then there is, FIRSTOP (B )? FIRST ()
5.3 calculate LASTOP:
If the formula B->... B or B->... Cb is generated, then B 'LASTOP (B)
If there is formula A->... B, there is, LASTOP (B )? LASTOP (B)
5.4 analyzer's four actions:
1) Import: Move the next input symbol to the stack.
2) Reduction: Replace the handle on the top of the stack with the non-Terminator on the left of the generative formula (right part of a generative formula)
3) accept: Analysis successful
4) error: Error Handling
5.5 operator priority grammar is actually LPP (leftmost plain phrase)
LR actually recognizes the active prefix (This prefix does not contain any symbols on the right of the corresponding sentence handle)
5.6 plain phrase:
1. A plain phrase is a phrase.
2. It contains at least one Terminator.
3. phrase that does not contain any Terminator except itself
NLR (0) analysis method does not need to view the input symbol forward. You only need to determine the action to be taken next based on the current stack top status.
LR (0) project set: the production formula marked with dots in a position on the right is called the LR (0) project of the corresponding grammar.
N reduction project: S → bBB. n Shift project: S →. bBBn pending project: S → B. bb s → bB. B
CFG is not always LR (0) syntax.
SLR (1): view an input symbol forward to determine whether the current contract can be reduced.
LR (1 ):
Test:
GRAMMAR:
S => 0S0
S => 1S1
S => 01
1. Calculate the SLR (1) project set standard family of this syntax,
Construct a DFA for identifying all the regular sentence prefixes
2. Is this SLR (1) syntax? If yes, give its SLR (1) analysis table,
If not, describe the reason.
1.
S'->. S
S'-> S.
S->. 0S0
S-> 0. S0
S-> 0S. 0
S-> 0S0.
S->. 1S1
S-> 1. S1
S-> 1 S. 1
S-> 1S1.
S->. 01
S-> 0.1
S-> 01.
2.