4 ms·
As far as I can tell, parser generators are harder to use and understand than recursive descent parsers because they involve feeding an abstract spec of your la
by joe_the_user 11y ago
As far as I can tell, parser generators are harder to use and understand than recursive descent parsers because they involve feeding an abstract spec of your language into a tool designed for any language whereas a recursive descent parser involves creating a tool more or less specific to your language.
Now, it seems to me that being easier to use and understand is an inherent advantage - I can't see how easier to understand doesn't make bugs easier to understand and so-forth.
Moreover, constructing a recursive descent parser involves understanding and transforming your language, an exercise which can also discover ambiguities and give a "deeper" understanding as well. It's hard for me to see Bison commands + code fragments as the ultimate in illumination concerning one's language's properties.
- jstimpfle 11y agoI've looked at yacc + bison a couple times and always turned away before even attempting to write parsers in them. It's ugly as hell and I figure sprinkling code is hard to understand and thus insecure. However, have you tried parser combinators? Parsec (a Haskell library) is really nice if it fits your grammar. Here is one guy who simulated that in Python, also very nice: http://jayconrod.com/posts/37/ http://jayconrod.com/posts/37/
- kccqzy 11y agoParsec is good but it's a rather old library. For more specialised needs there are even better choices in Haskell: (taken from Gabriel Gonzalez's recent post) * attoparsec remains the king of speed, generating parsers competitive in speed with C * trifecta remains the king of error messages, generating gorgeous clang-style errors * earley is a newcomer but deals with context-free grammars, while other parser combinatory are basically recursive descent parsers * and good old alex+happy for direct yacc+bison equivalent * I should probably mention that in certain simple cases you don't even need a parser combinator library to parse things. Just a good old `StateT (Text, r) [] ()` or similar can do wonders.