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.
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
Kwang-Moo Choe, outlines an algorithm for computing First(k) Sets and
Follow(k) Sets here:
http://plus.kaist.ac.kr/~choe/cs522/cs522/pdf/5par-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,
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]
Thanks again,
Carter.
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/cs522/pdf/5par-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,