Algorithm for computing first-k follow-k sets

This is a discussion on Algorithm for computing first-k follow-k sets within the Compilers forums in Theory and Concepts category; Hello, This is probably pretty elementary but I havent been able to locate a method to compute first-k follow-k sets (i.e. the k terminals derived from a symbol or following that symbol) efficiently for a grammar. Most textbooks only seem to cover the k = 1 case. Are there references out there which contain how to compute the generalization to k > 1? Thanks in advance, Carter....

Go Back   Application Development Forum > Theory and Concepts > Compilers

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-23-2008, 01:52 PM
Carter Cheng
Guest
 
Default Algorithm for computing first-k follow-k sets

Hello,

This is probably pretty elementary but I havent been able to locate a
method to compute first-k follow-k sets (i.e. the k terminals derived
from a symbol or following that symbol) efficiently for a grammar.
Most textbooks only seem to cover the k = 1 case. Are there references
out there which contain how to compute the generalization to k > 1?

Thanks in advance,

Carter.
Reply With Quote
  #2  
Old 08-23-2008, 07:18 PM
Hans-Peter Diettrich
Guest
 
Default Re: Algorithm for computing first-k follow-k sets

Carter Cheng schrieb:

> This is probably pretty elementary but I havent been able to locate a
> method to compute first-k follow-k sets (i.e. the k terminals derived
> from a symbol or following that symbol) efficiently for a grammar.
> Most textbooks only seem to cover the k = 1 case. Are there references
> out there which contain how to compute the generalization to k > 1?


With k>1 you'll have sets of k-tuples, which make the tables explode.
References to procedures have just been mentioned in this group (see
ANTLR...).

DoDi
Reply With Quote
  #3  
Old 08-24-2008, 04:08 PM
Felipe Angriman
Guest
 
Default Re: Algorithm for computing first-k follow-k sets

Carter, i think I've asked that question a while ago, but found no
satisfactory results.

Kwang-Moo Choe, outlines an algorithm for computing First(k) Sets and
Follow(k) Sets here:

http://plus.kaist.ac.kr/~choe/cs522/...par-SLL(k).pdf

but I THINK that the algorithm does not work on left-recursive
grammars (note: i haven't tried it)

The web site where i found the link is:
http://plus.kaist.ac.kr/~choe/

Regards,


On Sat, Aug 23, 2008 at 2:52 PM, Carter Cheng <cartercheng@gmail.com> wrote:

> This is probably pretty elementary but I havent been able to locate a
> method to compute first-k follow-k sets (i.e. the k terminals derived
> from a symbol or following that symbol) efficiently for a grammar.
> Most textbooks only seem to cover the k = 1 case. Are there references
> out there which contain how to compute the generalization to k > 1?

Reply With Quote
  #4  
Old 08-25-2008, 07:14 AM
Larry Evans
Guest
 
Default Re: Algorithm for computing first-k follow-k sets

On 08/24/08 15:08, Felipe Angriman wrote:
[snip]
> Kwang-Moo Choe, outlines an algorithm for computing First(k) Sets and
> Follow(k) Sets here:
>
> http://plus.kaist.ac.kr/~choe/cs522/...par-SLL(k).pdf


Page 1 of that pdf uses notation:

k:alpha beta

without defining what : means. My first guess is that it
takes the first k elements of an A^* if they exist; however,
that's not clear. Mr. Choe probably defines : in his
class room and say no need to repeat it on the .pdf.

>
> but I THINK that the algorithm does not work on left-recursive
> grammars (note: i haven't tried it)


Page 5 of that pdf says G (I guess a grammar)
is not LL(k) if G is left-recursive. so, I guess the
algorithm does not work on left-recursive grammars.

[snip]
Reply With Quote
  #5  
Old 08-25-2008, 08:33 AM
Larry Evans
Guest
 
Default 1:X in Choe's pdf (was Re: Algorithm for computing first-k follow-k sets

On 08/25/08 06:14, Larry Evans wrote:
> On 08/24/08 15:08, Felipe Angriman wrote:
> [snip]
>> Kwang-Moo Choe, outlines an algorithm for computing First(k) Sets and
>> Follow(k) Sets here:
>>
>> http://plus.kaist.ac.kr/~choe/cs522/...par-SLL(k).pdf

>
> Page 1 of that pdf uses notation:
>
> k:alpha beta
>
> without defining what : means.

[snip]
It's defined on page 18 of:

http://plus.kaist.ac.kr/~choe/cs522/cs522/pdf/1elt.pdf

Reply With Quote
  #6  
Old 08-25-2008, 01:55 PM
Carter Cheng
Guest
 
Default Re: 1:X in Choe's pdf (was Re: Algorithm for computing first-k follow-k sets

Thanks for the help everyone. For what I am doing I doubt I will need
to goto higher k values but I was just curious if methods for
computing these properties of a symbol in a grammar were readily
available.

Thanks again,

Carter.

Reply With Quote
  #7  
Old 08-26-2008, 10:40 AM
Felipe Angriman
Guest
 
Default Re: Algorithm for computing first-k follow-k sets

> Page 1 of that pdf uses notation:
>
> k:alpha beta
>
> without defining what : means. My first guess is that it
> takes the first k elements of an A^* if they exist; however,
> that's not clear. Mr. Choe probably defines : in his
> class room and say no need to repeat it on the .pdf.


This notation is defined in Terrence Parr PhD Thesis Page 5 that why
it isn't defined here
http://plus.kaist.ac.kr/~choe/cs522/...par-SLL(k).pdf

>>
>> but I THINK that the algorithm does not work on left-recursive
>> grammars (note: i haven't tried it)


>Page 5 of that pdf says G (I guess a grammar)
>is not LL(k) if G is left-recursive. so, I guess the
>algorithm does not work on left-recursive grammars.


My comment regarding the applicability of the algorithm to Left
Recursive Grammars is because Carter never said he wanted to compute
tables for LL(k) Grammars (which might be the most fitting supposition
since this is a compiler discussion list). However, if i consider the
request made by carter as is, i was compelled to answer in the manner
i did before.

Regards,
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:24 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.