Question

I am looking for the best solution for a LALR parser generator for C++ that will allow me to generate really good error messages. I really hate the syntax errors that MySQL generates and I want to take the parser in it and replace it with a "lint" checker that will tell me more than just

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a from users' at line 1

I have used YACC/LEX and BISON/FLEX. It has to work on Mac or Linux.

Was it helpful?

Solution

Why do you require LALR? One of the benefits of LL(k) parsers is that they can often make it easier to generate clear error messages. Most grammars that can be parsed by an LALR parser can be easily refactored to be parsable by an LL(k) parser.

ANTLR is a popular LL(k) parser generator that can generate C++ (as well as a number of other languages). From Chapter 10 of The Definitive ANTLR Reference:

The quality of a language application’s error messages and recovery strategy often makes the difference between a professional application and an amateurish application. Error recovery is the process of recovering from a syntax error by altering the input stream or consuming symbols until the parser can restart in a known state. Many hand-built and many non-LL-based recognizers emit less than optimal error messages, whereas ANTLR-generated recognizers automatically emit very good error messages and recover intelligently, as shown in this chapter.

Many grammars are also available for ANTLR, including a MySQL grammar.

OTHER TIPS

If you find that ANTLR doesn't completely solve your problem then you might consider basil. It is an LR(1) parser generator that was designed and written to create a C++ parser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top