3 ms·
I like PEGs a lot and even wrote my own PEG-like parsing language. The main problem I found was that, in practice, mixing lexing and parsing is a bad idea, so
by chubot 10y ago
I like PEGs a lot and even wrote my own PEG-like parsing language. The main problem I found was that, in practice, mixing lexing and parsing is a bad idea, so I have separate lexing in my system. It depends on the language, but I would say it's true for all programming languages.
It's just obvious that programming languages have separate lexical and grammatical structure. If you want to disprove that, show me some languages like C, Java, Python, etc. expressed as PEGs.
PEGs have been around for 12 years now; I don't see them being deployed widely. There are probably multiple reasons for that, but I believe usability in terms of expressing real languages is a big one. (People always harp on ordered choice; I don't think it's that big a deal because when you write a recursive descent parser, you're mostly using ordered choice too.)
You want to do as much work in the less powerful computational paradigm as possible -- that is, lex with regular languages. And then use the more powerful paradigm (PEGs or CFG algorithms) on top of that token stream.
I believe that lexing and parsing were combined in PEGs for reasons of academic presentation and bootstrapping, not for usability or practicality for recognizing real languages.
Several of your other points are wrong, but I'll leave it at that.
- sklogic 10y ago> mixing lexing and parsing is a bad idea Why exactly? I find it rather liberating to mix lexing and parsing, for any possible language. > show me some languages like C, Java, Python, etc. expressed as PEGs. Feel free to browse my github repos, username 'combinatorylogic'. There is a lot of parsers in PEG, including C and Verilog. One of the very good reasons to do such a mix is to be able to have nested comments (which rules out regular expressions). > I don't see them being deployed widely Do you see any new languages deployed widely? Inertia is very strong here. > Several of your other points are wrong, but I'll leave it at that. Mind elaborating? All my points are based on years of practice in writing parsers for all languages imaginable.