|
From: | Hans Aberg |
Subject: | Re: bison/flex: Best practice to report an libc error to caller of yyparse |
Date: | Sat, 13 Jun 2009 19:56:39 +0200 |
On 13 Jun 2009, at 17:55, Nicolai Stange wrote:
i wonder how to report an libc error(maybe ENOMEM, EIO) that has occured in either yylex or yyparse to thecaller of yyparse.As for the first error, memory allocation error, your program is likely unrecoverable, so just write an error message and exit.There are three reasons why I don't want to do that. 1.) On EIO it could be possible for the program to continue, with some other file for example.
THat would not work on ENOMEM (* Not enough memory *)
2.) Sometimes later on the parser could be incorporated within a library and to my knowledge a library should not print any text if it's not itsparticular intention.
Then you will have to take measures to turn off all other parser/lexer error messages. There is a difference between stdout and stderr, too.
3.) I want to have some general error handling mechanism, independent ofthe actual libc error code or what else has happened.
You can use C++ and throw and catch exceptions. When generating a parser error, though, it will try to recover (see Bison manual).
For other errors, I had to write in .l: #define YYERRCODE 256What's the difference in using %token YYERRCODE that doesn't rely on bison internals instead?
When the Bison parser sees 256 (or so I remember), it will generate a parser error. When it sees %token YYERRCODE that is just a normal token, you still have to figure out how to generate an error in the parser.
Hans
[Prev in Thread] | Current Thread | [Next in Thread] |