Just an anecdote with some fond memories that were made possible by Postgres and its internals. Postgres has a place in my heart for that, and being a damn fine DB of course!
Just an anecdote with some fond memories that were made possible by Postgres and its internals. Postgres has a place in my heart for that, and being a damn fine DB of course!
If you're learning this stuff you need a simple challenge to work through the end.
With regards to lex and yacc, I absolut detest these tools. They are horrible but they do work. And if you just want a functioning parser they'll do. My main criticism of these tools are the horrible errors you might end up with and the lack of sensible extension points.
If it is your first foray into parsers, I do think a simple grammar and handwritten lexer/parser is a good first step. Iterate some on that, then use tools to help with the verbose stuff.
Though to be honest, I enjoy writing parsers by hand. So, I'm a bit biased.
The big thing for this particular project was all the pitfalls of C with having to track memory allocations and passing arrays of pointers around and mentally keeping track. Yacc streamlined this a lot. If this was a production project and not a class I took along side four other, hand writing would be a serious option I'd consider (mostly for error reporting purposes like you mentioned), but I might even lean towards getting an MVP done in a parser generator and eventually converting over to handwritten if the need arose.
What?
On my compilers class, I was explicitly asked to use lex and yacc. Sure, for the very first assignment on that class we were asked to write the lexer by hand. But when it came to actually do the interesting parts, lex and yacc it was.
Hand-written lexer/parser means you can be dumb as a doornail and just walk through the logic.
As an aside, it also gives you a better ability to write error messages, and an easier time debugging compared to autogenerated solutions.
This is not true. Instead of trying to use error recovery feature of parser genrator, you can just add error case to your grammar, and it works as well as hand-written parser. Parser generator error recovery is pure bonus on top.
> and an easier time debugging compared to autogenerated solutions
This is also not true. Most parser generators (certainly lex/yacc) have good enough debug support that you never see generated code while you debug.
We got an A on that first parser that was hand written as well, but once we got to DML, I felt like we could really use tools given our time frame.
Implementing your own WAL + storage API for example, is more something along the lines I would expect.
Those compilers classes turned out to be pretty useful. I ended up having to build custom parsers several times in my career... including an SQL parser.