First off, real world languages generally don't use parser generators. Parser generators are also harder to learn, and are another dependency and build step. So you can happily skip.
Parsers are fun to write maybe once or twice but honestly one of the least exciting and most time consuming things to write. Use a parser generator if you can!
”When you can”, is nothing I disagree with, but also bad advice in that it doesn’t give any criteria.
For example: if you are writing the parser for a compiler you will spend years on, then a handwritten parser is great! You can tweak error handling easily and do all sorts of things in an easy to read and understand manner.
If you are writing a tool that will take some code and transform or analyse it in some way which isn’t a full-blown compiler, then a parser generator is nice to focus on the actual meat of the problem.
I personally love the book „Engineering a Compiler“ by Cooper & Torczon. Its got the perfect mix of theory and practice and helped me a lot understanding the whole subject. No prser generators and dependencies is a huge bonus too, the first chapters quickly get you up to speed with lexing and various methods of parsing.
3 comments
[ 2.5 ms ] story [ 19.8 ms ] threadFor example: if you are writing the parser for a compiler you will spend years on, then a handwritten parser is great! You can tweak error handling easily and do all sorts of things in an easy to read and understand manner.
If you are writing a tool that will take some code and transform or analyse it in some way which isn’t a full-blown compiler, then a parser generator is nice to focus on the actual meat of the problem.