13

On the web, there is a lot of examples showing how to construct parsing tables for a context-free grammar from first/follow sets for LL(1) parser.

But I haven't found anything useful related to k>1 cases. Even wikipedia gives no info about this.

I expect that it must be in some way similar, but pointers to existing research in this area would be very helpful.

Petr Kozelka
  • 7,670
  • 2
  • 29
  • 44
  • I have a copy of a great book on parsing that, unfortunately, skips this topic. I'm just as curious as you are. From my understanding, though, the algorithms for k > 1 are substantially more involved and completely infeasible in practice. I guess we'll find out! – templatetypedef Jan 25 '12 at 10:27
  • 3
    I dont think it's infeasible. At least ANTLR claims for parsing LL(K) (with any K) grammars. – Odobenus Rosmarus Jan 25 '12 at 13:01
  • With recursive descent parsers its easy, you just maintain a list of look aheads. Then there are plenty of optimization to improve on this, such as memoization and back tracking. Not sure how it would work for a table driven parser though! Have you figured it out yet? – Austin Henley Jan 28 '12 at 17:25
  • not really - but use a dirty workarround: lexical analyzer part "wraps" some multi-symbols as one, and then I use LL(1). However, this solution has limitations. I am using table-driven parser, because it seems to have best performance. – Petr Kozelka Feb 28 '12 at 13:19
  • from a mathematical point of view the strings in the first and follow set are k characters long, rather than just a single character. from an implementation point of view how you actually match these depends on how you represent your tokens I suppose. – Will Oct 13 '12 at 21:23
  • [This](http://slkpg.byethost7.com/llkparse.html) is everything you need to know about LL(k) parsing, including the description and comparison of several table-based algorithms. I can also suggest looking into [LL(*)](http://www.antlr.org/papers/LL-star-PLDI11.pdf) by Terence Parr. It is the algorithm which is used in [ANTLR](http://antlr.org). Another valuable source of information on LL(k) parsing is [Terence Parr's PhD thesis](http://www.antlr.org/papers/parr.phd.thesis.pdf). – Max Mouratov Oct 31 '12 at 17:13

1 Answers1

1

I struggle pretty much with the same issues, building LR parser, not LL though. I found a little better page than LL(k) mentioned by @cakeplus -- http://www.seanerikoconnor.freeservers.com/ComputerScience/Compiler/ParserGeneratorAndParser/QuickReviewOfLRandLALRParsingTheory.html There is also related paper available for free -- http://ci.nii.ac.jp/naid/110002673618/

However even those didn't help me much. So I started myself from the basics. If anyone is interested: https://aboutskila.wordpress.com/2013/06/14/lalrk-first-sets/ and the battle will continue :-)

greenoldman
  • 16,895
  • 26
  • 119
  • 185
  • I wish I could find an algorithm to calculate those. I'll probably reverse engineer [this](http://www.fit.vutbr.cz/~ikocman/llkptg/). – paulotorrens Sep 26 '16 at 17:56
  • 1
    @paulotorrens, start with "Aho, A.V., Ullman, J.D.: The Theory of Parsing, Translation, and Compiling, Volume I: Parsing." (it is from around 1970, classic Dragon Book misses this algorithm). The explanation is somewhat short, but solid and based on that you should be able to write your program. – greenoldman Sep 26 '16 at 19:17