How to find the FIRST set

E→TE’
E’→+TE’|ε
T→FT’
T’→*FT’|ε
F→(E)|i

F I R S T FIRST The
method ofobtaining the F I R S T set isas follows:
1.X ∈ VTX∈VTXV T (terminal symbol set)
FIRST (X) = X FIRST(X)={X}FIRST(X)=X (ie: the FIRST set of the terminator is still itself).

2、 X ∈ V N X∈VN XV N (the set of non-terminal symbols)
(1) IfX → a… X → a…Xa , Then a joinFIRST (X) FIRST(X)F I R S T ( X ) ; if there isX → ε X → εXε , then ε is added toFIRST (X) FIRST(X)F I R S T ( X ) (a is the first terminal symbol X can be introduced).
(2) If X→Y..., and Y∈VN, thenFIRST (Y) FIRST(Y)All non-ε elements in F I R S T ( Y ) are added toFIRST (X) FIRST (X)F I R S T ( X )
(3) 若有X → Y 1 Y 2 Y 3… YKX → Y_1Y_2Y_3… Y_KXAND1AND2AND3ANDK,且 Y i ∈ V N Y_i∈VN ANDiVN , ε ∈ F I R S T ( Y j ) ε∈FIRST(Yj) eFIRST(Yj) ,则 F I R S T ( Y i ) FIRST(Y_i) FIRST(Yi) The non-ε element in themiddle isadded toFIRST (X) FIRST (X)F I R S T ( X ) ; if allFIRST (Y j) FIRST(Yj)F I R S T ( Y j ) all containε εε, 则ε εε加入 F I R S T ( X ) 。 FIRST(X)。 FIRST(X)

Guess you like

Origin blog.csdn.net/qq_41870170/article/details/114658396