src/driver.cc

Go to the documentation of this file.
00001 // $Id: driver.cc 17 2007-08-19 18:51:39Z tb $
00004 #include <fstream>
00005 #include <sstream>
00006 
00007 #include "driver.h"
00008 #include "parser.h"
00009 #include "scanner.h"
00010 
00011 namespace example {
00012 
00013 Driver::Driver(class CalcContext& _calc)
00014     : trace_scanning(false),
00015       trace_parsing(false),
00016       calc(_calc)
00017 {
00018 }
00019 
00020 bool Driver::parse_stream(std::istream& in, const std::string& sname)
00021 {
00022     streamname = sname;
00023 
00024     Scanner scanner(&in);
00025     scanner.set_debug(trace_scanning);
00026     this->lexer = &scanner;
00027 
00028     Parser parser(*this);
00029     parser.set_debug_level(trace_parsing);
00030     return (parser.parse() == 0);
00031 }
00032 
00033 bool Driver::parse_file(const std::string &filename)
00034 {
00035     std::ifstream in(filename.c_str());
00036     return parse_stream(in, filename);
00037 }
00038 
00039 bool Driver::parse_string(const std::string &input, const std::string& sname)
00040 {
00041     std::istringstream iss(input);
00042     return parse_stream(iss, sname);
00043 }
00044 
00045 void Driver::error(const class location& l,
00046                    const std::string& m)
00047 {
00048     std::cerr << l << ": " << m << std::endl;
00049 }
00050 
00051 void Driver::error(const std::string& m)
00052 {
00053     std::cerr << m << std::endl;
00054 }
00055 
00056 } // namespace example

Generated on Mon Aug 20 13:34:21 2007 for Flex Bison C++ Example by  doxygen 1.5.2