From bb32f4f284d5e86ad24f0684e16e19243c1957f2 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 16 Jan 2007 13:11:30 +0000 Subject: [PATCH] * 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. --- ChangeLog | 10 ++++++++++ doc/bison.texinfo | 27 +++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e8b5511..1a097f9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-01-16 Akim Demaille + + * 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. + 2007-01-16 Akim Demaille * data/lalr1.cc (yy_reduce_print_): Add a missing end-of-line. diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 4c274574..0a9b83d4 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -34,7 +34,7 @@ This manual is for @acronym{GNU} Bison (version @value{VERSION}, @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 @@ Similarly for the parser itself. @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 @@ calcxx_driver::~calcxx_driver () @{ @} -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 @@ void 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 @@ main (int argc, char *argv[]) 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 -- 2.45.2