1 / 5

Lecture # 14

Lecture # 14. Algorithm for table construction of Predictive Parser. FIRST (Revisited). FIRST(  ) = { the set of terminals that begin all strings derived from  } FIRST( a ) = { a } if a  T FIRST() = {} FIRST( A ) =  A  FIRST() for A   P FIRST( X 1 X 2 … X k ) =

wylie
Download Presentation

Lecture # 14

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture # 14 Algorithm for table construction of Predictive Parser

  2. FIRST (Revisited) • FIRST() = { the set of terminals that begin all strings derived from } • FIRST(a) = {a} if a  T • FIRST() = {} • FIRST(A) = A FIRST() for A  P • FIRST(X1X2…Xk) = if for all j = 1, …, i-1 :   FIRST(Xj) then add non- in FIRST(Xi) to FIRST(X1X2…Xk) if for all j = 1, …, k :   FIRST(Xj) then add  to FIRST(X1X2…Xk)

  3. FOLLOW • FOLLOW(A) = { the set of terminals that can immediately follow nonterminalA }FOLLOW(A) = • for all (B  A )  P doadd FIRST()\{} to FOLLOW(A) • for all (B  A )  Pand   FIRST() doadd FOLLOW(B) to FOLLOW(A) • for all (B  A)  P doadd FOLLOW(B) to FOLLOW(A) • ifA is the start symbol Sthen add $ to FOLLOW(A)

  4. Constructing an LL(1) Predictive Parsing Table for each production A  do for each a FIRST() do add A  to M[A,a]enddoif  FIRST() thenfor each b FOLLOW(A) do add A  to M[A,b]enddoendifenddoMark each undefined entry in M error

  5. Example Table E T E’E’ +TE’|  T F T’T’ *FT’|  F ( E ) | id

More Related