▲ | antononcube 4 days ago | ||||||||||||||||
It seems you are describing how functional parsers (aka parser combinators) work. (BTW, there is a "Parser combinators" section in the featured post/article.) | |||||||||||||||||
▲ | ckok 3 days ago | parent | next [-] | ||||||||||||||||
I believe the proper term for what i am describing is a recursive descent parser. With which it is also quite doable to generate proper error handling and even recovery. Some form of this is used in almost every production language I think. It has been years since I've written a proper parser but before that every time I had to write one I tried the latest and greatest first. ANTLR, coco/r, combinators. All the generated ones seemed to have a fatal flaw that hand writing didnt have. For example good error handling seemed almost impossible, very slow due to Infinite look ahead or they were almost impossible to debug to find an error in the input schema. In the end hand crafting seems to be faster and simpler. Ymmv. My point about the article was mostly that all the formal theory is nice but all it does is scare away people, while parsing is probably the simplest thing about writing a compiler. | |||||||||||||||||
▲ | marcosdumay 4 days ago | parent | prev [-] | ||||||||||||||||
The bad news about those is that it's easy to mindlessly create a parser that runs on exponential time. The good news is that this happens in the grammar definition. So once you define your language well, you don't have to watch for it anymore. | |||||||||||||||||
|