3 ms·
Pretty neat. One thing I've found that's nice about recursive descent parsers written by hand is that you provide useful and meaningful error messages. 'yacc'
by kabdib 12y ago
Pretty neat.
One thing I've found that's nice about recursive descent parsers written by hand is that you provide useful and meaningful error messages. 'yacc' was always just saying "error" (and if you helped, the lexer might even supply a line number).
A message like "Expected a number for operator +" is way better than "syntax error line 109 around column 30".
- kevinnk 12y agoI don't have experience with yacc, but bison can generate errors with almost that exact form. It's even possible to do Clang style underlining, although it takes some hand holding. That said, usually recursive descent gives better errors but in my experience it's mostly from better recovery.
- Animats 12y agoThat was bad design in "yacc". To get decent diagnostics out of a parser generator of that type, error outputs need to indicate the last point at which the parser was on a unique, successful path, and where the parser input stream is at the error. The problem in the input is between those two points. Between those points, the parser was working on several alternate possible parsings, none of which could be completed. Give the names of those grammar constructs to the user. So an error message should look like: struct point { float x, float y }; ^^^^^^^^^ Expected one of: <structure-variable-name> ; }