[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: Better error handling in calc++
From: |
Akim Demaille |
Subject: |
FYI: Better error handling in calc++ |
Date: |
Tue, 16 Jan 2007 14:12:09 +0100 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.92 (gnu/linux) |
Index: ChangeLog
from Akim Demaille <address@hidden>
* doc/bison.texinfo (Calc++ Parsing Driver): Let "parse" return an
error code.
(Calc++ Scanner): Exit with failure if we can't open the input
file.
Accept "-" standing for stdin.
(Calc++ Top Level): Print the result only if the parsing was
successful.
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.219
diff -u -u -r1.219 bison.texinfo
--- doc/bison.texinfo 9 Jan 2007 01:17:50 -0000 1.219
+++ doc/bison.texinfo 16 Jan 2007 13:11:24 -0000
@@ -34,7 +34,7 @@
@value{UPDATED}), the @acronym{GNU} parser generator.
Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998,
-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
@@ -7789,8 +7789,8 @@
@comment file: calc++-driver.hh
@example
- // Handling the parser.
- void parse (const std::string& f);
+ // Run the parser. Return 0 on success.
+ int parse (const std::string& f);
std::string file;
bool trace_parsing;
@end example
@@ -7831,15 +7831,16 @@
@{
@}
-void
+int
calcxx_driver::parse (const std::string &f)
@{
file = f;
scan_begin ();
yy::calcxx_parser parser (*this);
parser.set_debug_level (trace_parsing);
- parser.parse ();
+ int res = parser.parse ();
scan_end ();
+ return res;
@}
void
@@ -8135,8 +8136,13 @@
calcxx_driver::scan_begin ()
@{
yy_flex_debug = trace_scanning;
- if (!(yyin = fopen (file.c_str (), "r")))
- error (std::string ("cannot open ") + file);
+ if (file == "-")
+ yyin = stdin;
+ else if (!(yyin = fopen (file.c_str (), "r")))
+ @{
+ error (std::string ("cannot open ") + file);
+ exit (1);
+ @}
@}
void
@@ -8165,11 +8171,8 @@
driver.trace_parsing = true;
else if (*argv == std::string ("-s"))
driver.trace_scanning = true;
- else
- @{
- driver.parse (*argv);
- std::cout << driver.result << std::endl;
- @}
+ else if (!driver.parse (*argv))
+ std::cout << driver.result << std::endl;
@}
@end example
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: Better error handling in calc++,
Akim Demaille <=