g2o
Public Member Functions | Public Attributes | List of all members
SlamParser::Driver Class Reference

#include <driver.h>

Collaboration diagram for SlamParser::Driver:
Collaboration graph
[legend]

Public Member Functions

 Driver (class SlamContext &slamContext_)
 construct a new parser driver context More...
 
bool parse_stream (std::istream &in, const std::string &sname="stream input")
 
bool parse_string (const std::string &input, const std::string &sname="string stream")
 
bool parse_file (const std::string &filename)
 
void error (const class location &l, const std::string &m)
 
void error (const std::string &m)
 

Public Attributes

bool trace_scanning
 enable debug output in the flex scanner More...
 
bool trace_parsing
 enable debug output in the bison parser More...
 
std::string streamname
 stream name (file or input stream) used for error messages. More...
 
class Scannerlexer
 
class SlamContextslamContext
 

Detailed Description

Definition at line 37 of file driver.h.

Constructor & Destructor Documentation

SlamParser::Driver::Driver ( class SlamContext slamContext_)

construct a new parser driver context

Definition at line 37 of file driver.cpp.

37  :
38  trace_scanning(false),
39  trace_parsing(false),
40  slamContext(slamContext_)
41  {
42  }
bool trace_scanning
enable debug output in the flex scanner
Definition: driver.h:44
class SlamContext & slamContext
Definition: driver.h:93
bool trace_parsing
enable debug output in the bison parser
Definition: driver.h:47

Member Function Documentation

void SlamParser::Driver::error ( const class location l,
const std::string &  m 
)

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

Definition at line 72 of file driver.cpp.

Referenced by SlamParser::Parser::error().

74  {
75  std::cerr << l << ": " << m << std::endl;
76  }
void SlamParser::Driver::error ( const std::string &  m)

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

Definition at line 78 of file driver.cpp.

79  {
80  std::cerr << m << std::endl;
81  }
bool SlamParser::Driver::parse_file ( const std::string &  filename)

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

Parameters
filenameinput file name
Returns
true if successfully parsed

Definition at line 59 of file driver.cpp.

References parse_stream().

60  {
61  std::ifstream in(filename.c_str());
62  if (!in.good()) return false;
63  return parse_stream(in, filename);
64  }
bool parse_stream(std::istream &in, const std::string &sname="stream input")
Definition: driver.cpp:44
bool SlamParser::Driver::parse_stream ( std::istream &  in,
const std::string &  sname = "stream input" 
)

Invoke the scanner and parser for a stream.

Parameters
ininput stream
snamestream name for error messages
Returns
true if successfully parsed

Definition at line 44 of file driver.cpp.

References lexer, SlamParser::Parser::parse(), SlamParser::Scanner::set_debug(), streamname, trace_parsing, and trace_scanning.

Referenced by main(), parse_file(), parse_string(), and SlamParser::ParserInterface::parseCommand().

45  {
46  streamname = sname;
47 
48  Scanner scanner(&in);
49  scanner.set_debug(trace_scanning);
50  this->lexer = &scanner;
51 
52  Parser parser(*this);
53 #if YYDEBUG
54  parser.set_debug_level(trace_parsing);
55 #endif
56  return (parser.parse() == 0);
57  }
bool trace_scanning
enable debug output in the flex scanner
Definition: driver.h:44
bool trace_parsing
enable debug output in the bison parser
Definition: driver.h:47
class Scanner * lexer
Definition: driver.h:89
std::string streamname
stream name (file or input stream) used for error messages.
Definition: driver.h:50
bool SlamParser::Driver::parse_string ( const std::string &  input,
const std::string &  sname = "string stream" 
)

Invoke the scanner and parser on an input string.

Parameters
inputinput string
snamestream name for error messages
Returns
true if successfully parsed

Definition at line 66 of file driver.cpp.

References parse_stream().

67  {
68  std::istringstream iss(input);
69  return parse_stream(iss, sname);
70  }
bool parse_stream(std::istream &in, const std::string &sname="stream input")
Definition: driver.cpp:44

Member Data Documentation

class Scanner* SlamParser::Driver::lexer

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 89 of file driver.h.

Referenced by parse_stream().

class SlamContext& SlamParser::Driver::slamContext

Reference to the calculator context filled during parsing of the expressions.

Definition at line 93 of file driver.h.

Referenced by SlamParser::Parser::parse().

std::string SlamParser::Driver::streamname

stream name (file or input stream) used for error messages.

Definition at line 50 of file driver.h.

Referenced by SlamParser::Parser::parse(), and parse_stream().

bool SlamParser::Driver::trace_parsing

enable debug output in the bison parser

Definition at line 47 of file driver.h.

Referenced by main(), and parse_stream().

bool SlamParser::Driver::trace_scanning

enable debug output in the flex scanner

Definition at line 44 of file driver.h.

Referenced by main(), and parse_stream().


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