Google Groups Home
Help | Sign in
First And Follow
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Mr.E  
View profile
 More options Jun 23, 3:39 pm
Newsgroups: comp.compilers
From: "Mr.E" <mr.waver...@verizon.net>
Date: Mon, 23 Jun 2008 12:39:31 -0700 (PDT)
Local: Mon, Jun 23 2008 3:39 pm
Subject: First And Follow
Can a first and follow set be derived from a tree?

As many texts as I've read on the subject I've been unable to create
first and follow sets.  I unfortunately don't understand the math
(though I got an A in discrete mathematics) or maybe I just cant
understand all the symbols or think abstractly enough.  In either case
I've met with repeated failure attempting to obtain a first and follow
from a grammar.  I had an idea the other day which I thought may
work.  I wondered is it possible to derive the first and follow sets
of a grammar by building a tree (or graphs) of the grammar.  I was
thinking that maybe if I did a first depth search through a tree that
I could pull this off.  After further contemplation I wasn't sure if I
could identify the follow set or possible recursions (I think they are
referred to as cycles?).

I realize I could enter grammar into some programs and they would
output what I desired but I'm still intent on being able to do this,
even if it isn't by a conventional or efficient method, so long as I
can understand it.

Thank you for any guidance you can provide,

W.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Evans  
View profile
 More options Jun 23, 11:17 pm
Newsgroups: comp.compilers
From: Larry Evans <cppljev...@suddenlink.net>
Date: Mon, 23 Jun 2008 22:17:50 -0500
Local: Mon, Jun 23 2008 11:17 pm
Subject: Re: First And Follow
On 06/23/08 14:39, Mr.E wrote:

> Can a first and follow set be derived from a tree?

See:

http://www.boostpro.com/vault/index.php?action=downloadfile&filename=...

which is based on:

http://www.boostpro.com/vault/index.php?action=downloadfile&filename=...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max Hailperin  
View profile
 More options Jun 24, 9:19 am
Newsgroups: comp.compilers
From: Max Hailperin <m...@gustavus.edu>
Date: Tue, 24 Jun 2008 08:19:38 -0500
Local: Tues, Jun 24 2008 9:19 am
Subject: Re: First And Follow

"Mr.E" <mr.waver...@verizon.net> writes:
>...
> As many texts as I've read on the subject I've been unable to create
> first and follow sets.  I unfortunately don't understand the math
> (though I got an A in discrete mathematics) or maybe I just cant
> understand all the symbols or think abstractly enough.

I'd suggest that these limitations can be overcome.  Though you
haven't yet understood the math, with some coaching, I bet you could.
(I've helped plenty of students through it who hadn't earned As in
discrete math.)

Whether you take that approach or whether you take the approach you
suggest, of looking for a graph formulation, you will make your own
life easier if you first limit yourself to grammars where no
productions have empty right-hand sides (conventionally written using
the Greek letter epsilon).  Once you have mastered that limited case,
then you can go back to considering the more general case.

> ... I wondered is it possible to derive the first and follow sets
> of a grammar by building a tree (or graphs) of the grammar. ...

Finding the FIRST sets is a straightforward graph problem in the case
with no empty right-hand sides. Build a directed graph with one vertex
for each terminal or nonterminal symbol.  For each production in the
grammar, the graph should have a directed edge from the nonterminal
symbol that is the production's left-hand side to the leftmost of the
symbols appearing on the production's right-hand side. (This might be
either a terminal symbol or a nonterminal symbol.)  To find the FIRST
set of a symbol, you just find the set of terminals that you can reach
in the directed graph starting from the given symbol.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max Hailperin  
View profile
 More options Jun 24, 4:35 pm
Newsgroups: comp.compilers
From: Max Hailperin <m...@gustavus.edu>
Date: Tue, 24 Jun 2008 15:35:16 -0500
Local: Tues, Jun 24 2008 4:35 pm
Subject: Re: First And Follow

"Mr.E" <mr.waver...@verizon.net> writes:
> ...  I wondered is it possible to derive the first and follow sets
> of a grammar by building a tree (or graphs) of the grammar. ...

I realized belatedly that my first response addressed this question
only for FIRST sets, not for FOLLOW sets.  Perhaps that was because
the directed graph construcion is more complicated for FOLLOW sets.
Nonetheless, here it is, once again using the simplifying assmption of
no empty right-hand sides (epsilon productions):

(1) Make a directed graph with one vertex for each nonterminal or
terminal symbol, as well as one for the special end-of-input marker,
which is conventionally written as $.

(2) Add a directed edge from the grammar's start symbol to $.

(3) For each production in the grammar, consider in turn each of the
symbols on the right-hand side with the exception of the rightmost
one.  If the symbol is a terminal, nothing needs doing.  But if it is
a nonterminal (let's say A), then look at the symbol that is
immediately after it in the production's right-hand side; let's call
that symbol x.  Note that x could be either a terminal or a
nonterminal symbol.  Consider in turn each element of FIRST(x); each
of these will be a terminal symbol, let's say b.  For each one, add a
directed edge from A to b.

(4) Consider in turn each production in the grammar that has a
nonterminal symbol as the rightmost symbol of its right-hand side.
Call that rightmost symbol A and the production's left-hand side B.
In each of these cases, add a directed edge from A to B.

Having built the directed graph in this way, then the FOLLOW set of
any nonterminal symbol consists of those terminal or end-of-input
symbols that are reachable from it.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul B Mann  
View profile
 More options Jun 25, 6:11 pm
Newsgroups: comp.compilers
From: "Paul B Mann" <p...@paulbmann.com>
Date: Wed, 25 Jun 2008 16:11:53 -0600
Local: Wed, Jun 25 2008 6:11 pm
Subject: Re: First And Follow

> Can a first and follow set be derived from a tree?

That question was answered a long time ago in this group, here is the
discussion:

http://compilers.iecc.com/comparch/article/01-04-088

Paul B Mann
http://lrgen.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mr.E  
View profile
 More options Jun 27, 5:59 pm
Newsgroups: comp.compilers
From: "Mr.E" <mr.waver...@verizon.net>
Date: Fri, 27 Jun 2008 14:59:29 -0700 (PDT)
Local: Fri, Jun 27 2008 5:59 pm
Subject: Re: First And Follow
Unfortunately, I have some mental roadblock that's prohibiting me from
being able to do this.  I played with trying to make a tool that would
list the first and follow sets no matter how inefficient it did it.  I
had a few ideas that I batted around.  I'll have to try again another
time.  I'm getting ready to start another semester and will have to
put my pet projects down again.

One day the light bulb will come on... sigh.

Mr. Evans - Thank you for the code.  I will do my best to study it.
Mr.Hailperin - Thank you for direction on how to create the first and
follow sets.
Mr. Mann - Thank you for directions to previous text on this subject.

Thank you all for your replies.

W.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google