00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <fstream>
00034 #include <sstream>
00035
00036 #include "torc/generic/parser/Driver.hpp"
00037 #include "torc/generic/parser/ParserHelpers.hpp"
00038 #include "torc/generic/om/PortAttributes.hpp"
00039 #include "torc/generic/om/NetAttributes.hpp"
00040 #include "torc/generic/parser/Scanner.hpp"
00041 #include "torc/generic/om/InterfaceAttributes.hpp"
00042 #include "torc/generic/om/LogicValueAttributes.hpp"
00043
00044 namespace torc {
00045 namespace generic {
00046
00047 Driver::Driver(const EdifContextSharedPtr &inEdifCntx)
00048 : mTraceScanning(false),
00049 mTraceParsing(false),
00050 mEdifCntx(inEdifCntx),
00051 mErrorObj() {
00052 }
00053
00054 Driver::~Driver() throw() {
00055 }
00056
00057 bool
00058 Driver::parseStream(std::istream& inStream,
00059 const std::string& inStreamName) {
00060 mStreamName = inStreamName;
00061
00062 Scanner scanner(&inStream);
00063 scanner.set_debug(mTraceScanning);
00064 this->mLexer = &scanner;
00065
00066 Parser parser(*this);
00067 parser.set_debug_level(mTraceParsing);
00068 return (parser.parse() == 0);
00069 }
00070
00071 bool
00072 Driver::parseFile(const std::string &inFileName) {
00073 std::ifstream in(inFileName.c_str());
00074 if (!in.good())
00075 {
00076 return false;
00077 }
00078 return parseStream(in, inFileName);
00079 }
00080
00081 bool
00082 Driver::parseString(const std::string &inString,
00083 const std::string& inStreamName) {
00084 std::istringstream iss(inString);
00085 return parseStream(iss, inStreamName);
00086 }
00087
00088 void
00089 Driver::error(const location& inLocation, const std::string& inMessage) {
00090 std::cerr << "There was error at:"<<
00091 inLocation << ": " << inMessage << std::endl;
00092 }
00093
00094 void
00095 Driver::error(const std::string& inMessage) {
00096 std::cerr << inMessage << std::endl;
00097 }
00098
00099 void
00100 Driver::setParserError( const Error &inSource) throw() {
00101 mErrorObj = ErrorSharedPtr( new Error(inSource) );
00102 }
00103
00104 }
00105 }