hylo-lang / Lotsawa

A Swift implementation of the MARPA algorithms
Apache License 2.0
18 stars 2 forks source link

Consider whether isLeoUnique (and isPenultUnique) is needed #4

Closed dabrahams closed 2 years ago

dabrahams commented 2 years ago

If uniqueness wasn't guaranteed by other features of the algorithm, it's hard to imagine that the Leo optimization would actually work for all grammars and inputs. Something seems a little bit fishy about this test, but I need to better understand the optimization before I can say.

dabrahams commented 2 years ago

According to @jeffreykegler IIUC, the grammars where non-unique transitional items can occur are not LR-regular, and thus not guaranteed by Leo to be parsed in linear time anyway. Open questions:

jeffreykegler commented 2 years ago

If we skip the check it certainly complicates the algorithm, which currently can assume for every ( Earley set, postdot symbol ) pair there is at most one Leo item. This uniqueness is relied on all over the place. For example, currently it is essential to the event mechanism, which needs to do Leo expansion on the fly.

I would want to do a theoretical examination to be sure all that trouble actually buys anything. Leo mentions this in his paper as an area for future research, which 30 years later it still is.

dabrahams commented 2 years ago

I certainly don't mean to suggest the check can be eliminated without a theoretical examination!

dabrahams commented 2 years ago

The check can't be eliminated, and was in fact not strict enough, as this test case demonstrates