Hacker News new | past | comments | ask | show | jobs | submit login

Lexers are easier to write by hand than parsers are but lexer generators such as flex are still very useful. The thing they are most useful at is that their algorithms always led the longest match possible, which is something that can be easy to get wrong by hand.

Regarding LALR parsers, the best thing about them is that they error out if they think your grammar might be ambiguous, which is specially useful if you are designing your own language. It is also easier to evolve a grammar if you build the parser with a high level tool than if you code everything by hand. For example, a top down parser needs to know at every point what are the valid lookahead tokens that might appear and adding a new rule to the grammar might require changing the lookahead tokens in many different spots.

The place were yacc doesn't shine is if your grammar isn't context free, in which case you might need to use hacky tricks or advanced parsing techniques. Bottom up parser generators also aren't the best at generating informative error messages (but they do a decent job of doing a bare minimum default error message)




Thank you very much - that's all useful - especially the bit about bottom up parser generators being not the best at generating informative error messages.


There are tools such as merr that help with this but generally its hard to beat hand-crafted error messages developed with love and sweat :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: