(warning: draft. And compiler-heavy.)
Classic recursive-descent parsing has an obvious problem: left-recursion becomes infinite recursion in the call stack.
A := A B | C
Technically, that grammar allows for `C B` to be a valid `A`, and same for `C B B`, and any number of Bs at the end. It's functionally equivalent to
A := C B*
This sort of equivalence is not always possible. Generalized LL parsing (GLL) is, in essence, a modified recursive descent which solves this, but all of the information I can find on it is dense academic bullshit.
GLL does two things: 1) It yields every possible successful parse tree, instead of just one successful one, and 2) it handles left-recursion automatically. It does these while still, fundamentally, being recursive descent, instead of needing to move to PEG or GLR or what have you.
But the 'magic' is actually really stupidly obvious once you struggle through the dozens of papers of overly dense language and symbols:
- First, when encountering a set of alternates, try _all of them_.
- Second, when encountering left-recursion, don't actually try parsing. Instead, _document that rule_ as a trigger.
Take that rule, A := A B. When you encounter that rule, _instead of actually trying to parse for an A_, register a trigger ("Whenever an A is matched, we must try to match A := A B, starting at the B, against that index"), and then _skip that alternate_.
Then, whenever matching a rule, check if there's any triggers against it and, if so, fire them - did we match an alternate that could fulfull a left-recursive rule? Okay, now we need to try that left-recursive rule!
If you just start from that first principle ("We can't actually parse the left-recursive rule until we know if an alternate matches"), and extrapolate the second principle from it ("Okay, so we need to try all alternates to know if there's any other rule that matches"), everything else emerges naturally.
How do you do that? Well, you try all alternates, and when we encounter one we can't, we note it down and give up, using that note to try again later when we have the info we'd need to do it.
@sinister @patrizia @buttplugio
If you want to be good at it and find it interesting, absolutely it's worthwhile. Hell, even pretending for a second that the AI shit was any good which, it's not
"Other people are so good at it, should I even bother trying?"
Uh, yeah, that's how you become one of those people you're looking up at!
Is there a value in cooking when you can just go the restaurant?
Or in sketching when you can just go to a museum?
Or in going outside when you can just look at a picture of it?
Yes. To all of these.
There's a value to skill. There's a value to learning skills. There's a value to finding the things you love and loving the things you find, and no technological "advance" or mass-produced sweatship-product will ever change that.
Learn how to manage memory manually, or how to write assembly. Write a compiler, or a web browser.
Learn how to repair your hardware when it breaks, and how to fix your software when the authors don't care to.
Teach yourself how to write, or draw, or sing, or whatever it is that you wish you knew.
You don't have to do any of this, of course - but if you're not going to, it should be because you don't want to, not because you've been lied to.
The hardest step is to admit that you are capable.
I met a song
It sang to me
Of lives I hadn't seen
I sang along
It laughed and called
And mocked the lives I lived
I turned away
Tears stained my face
I couldn't claim the pain
I met a song
It sang for me
The words I daren't say
I hummed along
It cried and raged
Together, fall and drift
I run through flame
Rhythm sustained
Replace what could have been
I met a song
It sang with me
Of words never believed
I laughed along
With tears so strong
and offered it my page.
