Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Hand-written parsers are even worse. Using an LR parser generator is worth the time investment.

I'm curious, what makes you say this? From what I've read online secondhand, people tend to recommend handwritten recursive descent parsing and Pratt/TDOP parsing, because it's easier to add good error messages and later add context sensitive productions (e.g. the way Clang resolves class-wide declarations while parsing C++: https://eli.thegreenplace.net/2012/07/05/how-clang-handles-t...).



He explains it in the linked video presentation which is worth watching: the value being that your parser generator will complain about any ambiguity in the grammar (shift-reduce conflicts) rather than having that show up as a β€œwat?” at runtime.

You might argue that this argument reduces to checking the grammar using static analysis similar to the order generator. But then handwriting the parser is still extra work and risk.


What I've seen most nontrivial projects do (and have done in a commercial product myself) is to start with a parser generator then move to hand written parsers when UX and polish become a bigger priority than exploring the problem space.

The parser generator grammar spec can then be used to generate random test cases and compare the output of the new parser with the old one to make sure they're identical.




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

Search: