2 ms·
How can recursive descent not work? Did you not do backtracking? It might be slow or annoying but it should work.
by dataflow 2y ago
How can recursive descent not work? Did you not do backtracking? It might be slow or annoying but it should work.
- HexDecOctBin 2y agoI mean, with enough hacking around, anything can work. But the code had gotten extremely complicated and brittle, and it was still not handling all the edge cases. Readability was important for this project, since I want to be able to modify the parser later to add new extensions to the language.
- dataflow 2y agoAh gotcha, thanks! Out of curiosity do you recall examples of any of the hardest cases it couldn't properly handle?
- HexDecOctBin 2y agoStuff like: char *(*(**foo[][8])())[]
- dataflow 2y agoAnd it would fail to parse at all, or parse as the wrong thing?
- HexDecOctBin 2y agoRecursive descent required too much backtracking and state resets, which made the code buggy and unreadable (and the error reporting was awful). Pratt parser simply parsed wrong (presumably because I couldn't figure out the right way to sort the precedences).
- dataflow 2y agoGotcha! I've been thinking of trying my hand at a C parser but it always gave me the sense that it was more annoying than it should be haha. Interesting to near your experience, thanks for sharing!