3 ms·
Why would you let the grammar dictate the architecture of your compiler? Left recursion in things like expressions is completely trivial to eliminate. If you w
by barrkel 9y ago
Why would you let the grammar dictate the architecture of your compiler?
Left recursion in things like expressions is completely trivial to eliminate. If you want to e.g. embed a DSL in a language, something that's really easy to do with recursive descent, it's worth spending 30 seconds or so to remove left recursion from your expression rules. Etc.
> You first write/immagine the grammar that you want to write, whatever is most intuitive for you.
IMO this is the road to hard to parse languages; if you genuinely advocate this path, you'll end up needing a GLR parser before you know it. I think it's much better to ensure your grammar is parseable with LL(1); not only is the tooling simpler, but the language will be less ambiguous for human users too. Follow the example of Pascal, not C++. This is what I'd advocate even for people doing hand-written recursive descent on a new language: validate your grammar with an LL(k) tool even if you don't use the generated parser.
(You've ended up sounding a bit like Ira Baxter, who's often seen around the net selling his DMS toolkit. He has a strong self-interest in people writing complicated grammars, so that he can sell them his services...)
- tom_mellior 9y ago> You've ended up sounding a bit like Ira Baxter Haha, I was thinking about him too. He does have a point, though, that on 2018 machines we might be able to afford parsing technology a bit more expensive than the 1970s approaches commonly used today.
- nnq 9y ago> but the language will be less ambiguous for human users too I'd bet against this. The human brain works very differently, we always keeps something like "trees of contexts" in our head. And why would you thing left recursions is less intuitive to a human user than other kinds of recursion. > ended up sounding a bit like Ira Baxter Now I gotta take time and google who this guy is :P