Compiler Principle (b) parsing

 

 

 

 Terminator general capital letters, nonterminal generally lowercase letters

On BNF predetermined <terminator>, nonterminal

Leftmost derivation, rightmost derivation

Parse tree:

 

 Ambiguous grammar:

 

 Top-down analysis:

 

 Correlation algorithm:

 

 Look symbols to avoid backtracking before use.

Recursive descent analysis algorithm:

 

 LL (1) analysis algorithm:

 

 Grammar recursively go Chuzuo reextracted left common factor, please FIRST set, NULLABLE in sets, set FOLLOW

FIRST集:

FIRST set to be extended to an arbitrary string:

 

 

 

 If LL (1) Analysis of the table there is a conflict does not belong grammar LL (1) grammar

FIRST set of the complete algorithm:

 

 General calculation LL (1) analysis table Note:

 

 NULLABLE集:

 

 NULLABLE set calculation process:

 

 FOLLOW set Calculated:

 

 Seeking LL (1) Process analysis table: please FIRST set -----> ------- requirements set NULLABLE> ------- requirements set FOLLOW> Set request FIRST_S -> seeking LL ( 1) analysis table (might get conflicts)

Construction LL (1) analysis table:

For LL (1) syntax analysis LL (1) analysis table

Resolve conflicts LL (1) analysis table:

1, the elimination of left recursion, recursive and right turns

 Eliminate indirect left recursion:

               

2, the left extracted common factor.

 

 

 

 

Bottom-up analysis, also known as Shift - reduce assay (the reverse process from top to bottom rightmost derivation):

 

      

 

Analysis steps:

      

Guess you like

Origin www.cnblogs.com/lq13035130506/p/12048784.html