torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::Driver Class Reference

#include <Driver.hpp>

+ Collaboration diagram for torc::generic::Driver:

Public Member Functions

bool parseStream (std::istream &inStream, const std::string &inStreamName="stream input")
 
bool parseString (const std::string &inString, const std::string &inStreamName="string stream")
 
bool parseFile (const std::string &inFileName)
 
void error (const class location &inLocation, const std::string &inMessage)
 
void error (const std::string &inMessage)
 
ScannergetLexer () const
 
std::string & getStreamName ()
 
EdifContextSharedPtr getContext () const
 
Error getParserError () const
 
bool getIsParserErrorSet () const
 
void setParserError (const Error &inSource)
 
 Driver (const EdifContextSharedPtr &inEdifCntx)
 construct a new parser driver context More...
 
 ~Driver () throw ()
 

Private Attributes

bool mTraceScanning
 
bool mTraceParsing
 
std::string mStreamName
 
ScannermLexer
 
EdifContextSharedPtr mEdifCntx
 
ErrorSharedPtr mErrorObj
 

Detailed Description

The Driver class brings together all components. It creates an instance of the Parser and Scanner classes and connects them. Then the input stream is fed into the scanner object and the parser gets it's token sequence. Furthermore the driver object is available in the grammar rules as a parameter. Therefore the driver class contains a reference to the structure into which the parsed data is saved.

Definition at line 48 of file Driver.hpp.

Constructor & Destructor Documentation

torc::generic::Driver::Driver ( const EdifContextSharedPtr inEdifCntx)

construct a new parser driver context

Definition at line 47 of file Driver.cpp.

47  : mTraceScanning(false),
48  mTraceParsing(false), mEdifCntx(inEdifCntx), mErrorObj() {}
ErrorSharedPtr mErrorObj
Definition: Driver.hpp:116
EdifContextSharedPtr mEdifCntx
Definition: Driver.hpp:113
torc::generic::Driver::~Driver ( )
throw (
)

Definition at line 50 of file Driver.cpp.

50 {}

Member Function Documentation

void torc::generic::Driver::error ( const class location inLocation,
const std::string &  inMessage 
)

Error handling with associated line number. This can be modified to output the error e.g. to a dialog box.

+ Here is the caller graph for this function:

void torc::generic::Driver::error ( const std::string &  inMessage)

General error handling. This can be modified to output the error e.g. to a dialog box.

Definition at line 81 of file Driver.cpp.

81  {
82  std::cerr << inMessage << std::endl;
83 }
EdifContextSharedPtr torc::generic::Driver::getContext ( ) const
inline

Definition at line 127 of file Driver.hpp.

127  {
128  return mEdifCntx;
129 }
EdifContextSharedPtr mEdifCntx
Definition: Driver.hpp:113

+ Here is the caller graph for this function:

bool torc::generic::Driver::getIsParserErrorSet ( ) const
inline

Definition at line 135 of file Driver.hpp.

135  {
136  return mErrorObj;
137 }
ErrorSharedPtr mErrorObj
Definition: Driver.hpp:116

+ Here is the caller graph for this function:

Scanner * torc::generic::Driver::getLexer ( ) const
inline

Definition at line 119 of file Driver.hpp.

119  {
120  return mLexer;
121 }

+ Here is the caller graph for this function:

Error torc::generic::Driver::getParserError ( ) const
inline

Definition at line 131 of file Driver.hpp.

131  {
132  return *mErrorObj;
133 }
ErrorSharedPtr mErrorObj
Definition: Driver.hpp:116

+ Here is the caller graph for this function:

std::string & torc::generic::Driver::getStreamName ( )
inline

Definition at line 123 of file Driver.hpp.

123  {
124  return mStreamName;
125 }
std::string mStreamName
Definition: Driver.hpp:105

+ Here is the caller graph for this function:

bool torc::generic::Driver::parseFile ( const std::string &  inFileName)

Invoke the scanner and parser on a file. Use parseStream with a std::ifstream if detection of file reading errors is required.

Parameters
inFileNameinput file name
Returns
true if successfully parsed

Definition at line 64 of file Driver.cpp.

64  {
65  std::ifstream in(inFileName.c_str());
66  if(!in.good()) {
67  return false;
68  }
69  return parseStream(in, inFileName);
70 }
bool parseStream(std::istream &inStream, const std::string &inStreamName="stream input")
Definition: Driver.cpp:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool torc::generic::Driver::parseStream ( std::istream &  inStream,
const std::string &  inStreamName = "stream input" 
)

Invoke the scanner and parser for a stream.

Parameters
inStreaminput stream
inStreamNamestream name for error messages
Returns
true if successfully parsed

Definition at line 52 of file Driver.cpp.

52  {
53  mStreamName = inStreamName;
54 
55  Scanner scanner(&inStream);
56  scanner.set_debug(mTraceScanning);
57  this->mLexer = &scanner;
58 
59  Parser parser(*this);
60  parser.set_debug_level(mTraceParsing);
61  return (parser.parse() == 0);
62 }
std::string mStreamName
Definition: Driver.hpp:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool torc::generic::Driver::parseString ( const std::string &  inString,
const std::string &  inStreamName = "string stream" 
)

Invoke the scanner and parser on an input string.

Parameters
inStringinput string
inStreamNamestream name for error messages
Returns
true if successfully parsed

Definition at line 72 of file Driver.cpp.

72  {
73  std::istringstream iss(inString);
74  return parseStream(iss, inStreamName);
75 }
bool parseStream(std::istream &inStream, const std::string &inStreamName="stream input")
Definition: Driver.cpp:52

+ Here is the call graph for this function:

void torc::generic::Driver::setParserError ( const Error inSource)

Definition at line 85 of file Driver.cpp.

85  {
86  mErrorObj = ErrorSharedPtr(new Error(inSource));
87 }
ErrorSharedPtr mErrorObj
Definition: Driver.hpp:116
boost::shared_ptr< Error > ErrorSharedPtr

+ Here is the caller graph for this function:

Field Documentation

EdifContextSharedPtr torc::generic::Driver::mEdifCntx
private

Reference to the Edif context filled during parsing of the Edif file.

Definition at line 113 of file Driver.hpp.

ErrorSharedPtr torc::generic::Driver::mErrorObj
private

Reference to the Error object

Definition at line 116 of file Driver.hpp.

Scanner* torc::generic::Driver::mLexer
private

Pointer to the current lexer instance, this is used to connect the parser to the scanner. It is used in the yylex macro.

Definition at line 109 of file Driver.hpp.

std::string torc::generic::Driver::mStreamName
private

Definition at line 105 of file Driver.hpp.

bool torc::generic::Driver::mTraceParsing
private

Definition at line 104 of file Driver.hpp.

bool torc::generic::Driver::mTraceScanning
private

Definition at line 103 of file Driver.hpp.


The documentation for this class was generated from the following files: