This is where recursive decent parsing really shines. When an invalid sequence is detected deep in the recursion, you don't have enough context to generate the best error message but as you unwind, you can add additional context such that by the time you're at the top of the call chain, you can generate very high quality error messages.
Of course, you have to be careful about dealing with recursion that's too deep. Large input files and/or grammars that require a lot of back tracking can make it a very slow parser too.
But for quite a lot of things, it's very appropriate. It's pretty much my go to mechanism when I need a custom parser.
Of course, you have to be careful about dealing with recursion that's too deep. Large input files and/or grammars that require a lot of back tracking can make it a very slow parser too.
But for quite a lot of things, it's very appropriate. It's pretty much my go to mechanism when I need a custom parser.