Are there any good examples of FIRST () and FOLLOW ()?

cosc143u@rosie.uh.edu (91F9774)
Sat, 20 Jun 1992 18:08:00 GMT

          From comp.compilers

Related articles
Are there any good examples of FIRST () and FOLLOW ()? cosc143u@rosie.uh.edu (1992-06-20)
Re: Are there any good examples of FIRST () and FOLLOW ()? jos@and.nl (1992-06-22)
Re: Are there any good examples of FIRST () and FOLLOW ()? andrewd@cs.adelaide.edu.au (1992-06-25)
Re: Are there any good examples of FIRST () and FOLLOW ()? andrewd@cs.adelaide.edu.au (1992-06-29)
| List of all articles for this month |
Newsgroups: comp.compilers
From: cosc143u@rosie.uh.edu (91F9774)
Keywords: LL(1), question
Organization: University of Houston
Date: Sat, 20 Jun 1992 18:08:00 GMT

We are going over predictive parsers right now (we won't actually be using
them for our project but have to know how to build them for the test). My
book has two examples total on these subjects and I just can't seem to
understand the FOLLOW () function. Does anyone out there have a good
explanation of the FOLLOW () function and how it is used in building the
predictive parse table?


Example:
    S->AB | epsilon
    A->aA
      | a
    B->BS
      | b


To remove left recursion I need to change B->BS to
    B->bB'
  B'->BS | eps.


FIRST (S) = {$} U FIRST (A) = {a}
FIRST (B) = {b}


FOLLOW (S) = {$,b}?
FOLLOW (A) = FIRST (B) = {b}?


PP table
          a b $
S S->AB S-> eps.
A A->a
      A->aA
B B->bB'
B' B'->BS


I'm pretty sure I have problems with this table but I can't see where.
Any comments are appreciated. The questions on the FOLLOW's indicate that
I'm not sure if that is the correct follow. In our book, "COMPILERS:
Principles, Techniques, and Tools", the "$" is in the FOLLOW of S by
definition. Apparently in some texts there would be an extra transition,
"S'->S | epsilon" that explains this...


Thanks in advance
---
Stephen McLeod
The Eternal Student
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.