g2o
Loading...
Searching...
No Matches
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
 
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
 
bool trace_parsing
 enable debug output in the bison parser
 
std::string streamname
 stream name (file or input stream) used for error messages.
 
class Scannerlexer
 
class SlamContextslamContext
 

Detailed Description

Definition at line 37 of file driver.h.

Constructor & Destructor Documentation

◆ Driver()

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

construct a new parser driver context

Definition at line 37 of file driver.cpp.

38 : trace_scanning(false),
39 trace_parsing(false),
40 lexer(nullptr),
41 slamContext(slamContext_) {}
bool trace_parsing
enable debug output in the bison parser
Definition driver.h:46
class SlamContext & slamContext
Definition driver.h:92
class Scanner * lexer
Definition driver.h:88
bool trace_scanning
enable debug output in the flex scanner
Definition driver.h:43

Member Function Documentation

◆ error() [1/2]

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 68 of file driver.cpp.

68 {
69 std::cerr << l << ": " << m << std::endl;
70}

◆ error() [2/2]

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 72 of file driver.cpp.

72{ std::cerr << m << std::endl; }

◆ parse_file()

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 57 of file driver.cpp.

57 {
58 std::ifstream in(filename.c_str());
59 if (!in.good()) return false;
60 return parse_stream(in, filename);
61}
bool parse_stream(std::istream &in, const std::string &sname="stream input")
Definition driver.cpp:43

References parse_stream().

◆ parse_stream()

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 43 of file driver.cpp.

43 {
44 streamname = sname;
45
46 Scanner scanner(&in);
47 scanner.set_debug(trace_scanning);
48 this->lexer = &scanner;
49
50 Parser parser(*this);
51#if YYDEBUG
52 parser.set_debug_level(trace_parsing);
53#endif
54 return (parser.parse() == 0);
55}
std::string streamname
stream name (file or input stream) used for error messages.
Definition driver.h:49

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().

◆ parse_string()

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 63 of file driver.cpp.

63 {
64 std::istringstream iss(input);
65 return parse_stream(iss, sname);
66}

References parse_stream().

Member Data Documentation

◆ lexer

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

Referenced by parse_stream().

◆ slamContext

class SlamContext& SlamParser::Driver::slamContext

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

Definition at line 92 of file driver.h.

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

◆ streamname

std::string SlamParser::Driver::streamname

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

Definition at line 49 of file driver.h.

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

◆ trace_parsing

bool SlamParser::Driver::trace_parsing

enable debug output in the bison parser

Definition at line 46 of file driver.h.

Referenced by main(), and parse_stream().

◆ trace_scanning

bool SlamParser::Driver::trace_scanning

enable debug output in the flex scanner

Definition at line 43 of file driver.h.

Referenced by main(), and parse_stream().


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