2

Usually LR(1) parsers construct the parse table offline, but this is not possible in the case of extensible syntax. Incrementally rebuilding the parse table is possible, but requires an expensive "garbage collection" step. A possibility that occurred to me is delaying the rebuild until the end of the current file, and in the mean time parsing directly from the grammar. However, I am not sure if this is possible for LR(1) grammars.

I think for LR(0) grammars, comparing the top of the parse stack to each production with longest-match-wins would be equivalent to the usual method, although obviously somewhat slower. However, I am unsure if this is possible for LR(1) grammars, at least without rebuilding substantial parts of the parse table at every step, or if it is, how I would go about it.

Is there a known way to do this? Or do I need to bite the bullet and do incremental table generation?

klkblake
  • 377
  • 2
  • 9
  • 1
    Good question. Incremental parse table generation looks like the way to go. It's not immediately clear what do you mean by "_garbage collection_". There was quite a bit of literature on incremental parser generation back in the late 1980s early 1990s. – Dima Chubarov Feb 09 '16 at 08:22
  • 1
    The paper I saw ("Incremental generation of LR parsers", Horspool 1990) required doing a scan to discard states that are no longer reachable from the start state after adding a new rule, which they analogised to garbage collection. – klkblake Feb 09 '16 at 08:37
  • @klkblake: "Expensive" in 1990 may not be particularly troublesome today. If you really want to use that algorithm (although it's not clear to me that it is appropriate for an extensible language, but that depends on precisely what type of extensibility you anticipate), you should try implementing it and then see if the computational cost is excessive. – rici Feb 09 '16 at 14:55
  • TL;DR: I'm a little late to the party, but I might have gotten a start. Take a look at the recursive ascent parser. – xilpex May 07 '20 at 22:42

0 Answers0