I've made really good progress on my LR(1) parser combinators.

The next step (which I'm feeling a little stuck on, mostly because I need more energy to actually figure it out and I do not have energy), is implementing the selective applicative functor bit.

Basically it allows for a finite amount of context sensitivity: as it is parsing, it gives the user's logic (formed from the parser combinators) the ability to reject parses during parsing.

There's one big problem that LR parsing is nondeterministic from the perspective of the combinators, so you don't know what combinator to apply to the rules at first. So it could be a little inaccurate.

For cases where there isn't ambiguity (shift/reduce or reduce/reduce conflicts), it doesn't make much sense to keep trying to refute the matches. Just let the LR algorithm do its thing.

It's pretty common to write LR grammars with tons of ambiguity and resolve them with token precedence – it's just a way to prioritize shift/reduce and reduce/reduce conflicts. I think this is called precedence operators, idk why. (Not operator precedence.)

But if you have that going on and selective parsing that allows you to reject cases, you must apply the selective rejection first, and then precedence operators.

This whole project has been an interesting adventure in different layers of logic and such like this: how they communicate and dialogue.

Anyways, if you're bored and want to follow along in the code:


You must log in to comment.