4 ms·
>Use a proper context-free grammar parser if you need to parse a context free grammar, you know? The thing is that regular expression are supported as language
by ginko 11y ago
>Use a proper context-free grammar parser if you need to parse a context free grammar, you know?
The thing is that regular expression are supported as language feature or as standard library in pretty much every language. If you want to build a proper parser, you'll have to jump through a lot more hoops. For instance for C++ I've tried tons of different lexer and parser generators and they all suck for various reasons. (Verbose syntax, uses global variables, C only, lexer not compatible with parser and vice versa,..) Most people seem to end up writing their own parsers from scratch.
The only time I've ever seen parsing done right is with Parsec for Haskell.
- hacker_9 11y agoIt's a mistake to write your own parser because they can get so complex so quickly to even do basic stuff, and you'll lose sight of the original goal of the project. See Prolog - a whole programming language built around the idea of parsing language (albeit NLP)! I suggest you take alook at Antrl4 for a powerful but easy to use parser plus lexer combo.
- ginko 11y agoI tried Antlr, even bought the book, and at least for C++ I found it pretty unworkable. Even with the book the documentation felt very incomplete. Maybe things work better on the Java side.
- bro-stick 11y agoAntlr is shit; it will waste your time for anything real. Bison+flex (once you figure out the quirks, undocumented assumptions and flags) and treetop are usable. https://www.gnu.org/software/bison/manual/ https://www.gnu.org/software/bison/manual/ http://flex.sourceforge.net/manual/ http://flex.sourceforge.net/manual/ http://treetop.rubyforge.org http://treetop.rubyforge.org Disclaimer: A long time ago in a galaxy, far, far away, I wrote an optimizing Java-to-MIPS compiler (sans GC, so leaky heap) in C++ using Flex/Bison and again in Java using JavaCC.
- bro-stick 11y agoMost apps link against PCRE.
- dankohn1 11y agoObligatory "You can't parse HTML with Regex" link: http://stackoverflow.com/a/1732454/1935918 http://stackoverflow.com/a/1732454/1935918
- wodenokoto 11y agoI really hate that link. Not only is it uninformative, I disagree with it. If you know the shape of your html data, parsing it with regular expressions can be much easier than with a dedicated parser.
- scott_karana 11y ago> If you know the shape of your html data, parsing it with regular expressions can be much easier than with a dedicated parser. If you know the shape of your HTML in advance, you're hardly "parsing" it. :)
- gavinpc 11y agoYou might be interested in OMeta, whose goal is to make language experimentation quicker and more accessible by providing a kind of interface layer between a declarative grammar and a host language. I'm still reading the paper, so I can't vouch for it yet. But it's from VPRI and has Alan Kay's backing.[0] [0] http://www.tinlizzie.org/ometa/ http://www.tinlizzie.org/ometa/
- jwmerrill 11y agoI really enjoyed learning OMeta, and I'd recommend playing with it to others. However, the performance of the JavaScript implementation is really bad. It uses exceptions as a primary mechanism for control flow, which is not generally well optimized in JS. I observed a toy calculator grammar parsing a string about 20 characters long throw and catch hundreds of exceptions. I've had good success with Jison as a JS parser generator that is performant enough to feel good about using in production.