IBAMR  IBAMR version 0.19.
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SAMRAI::tbox::Parser Class Reference

#include <tbox/Parser.h>

Classes

struct  ParseData
 

Public Member Functions

 Parser ()
 
 ~Parser ()
 
int parse (const std::string &filename, FILE *fstream, Pointer< Database > database)
 
int getNumberErrors () const
 
int getNumberWarnings () const
 
Pointer< Database > & getScope ()
 
void enterScope (const std::string &name)
 
void leaveScope ()
 
Pointer< DatabasegetDatabaseWithKey (const std::string &name)
 
bool pushIncludeFile (const std::string &filename)
 
void popIncludeFile ()
 
void error (const std::string &message)
 
void warning (const std::string &message)
 
void setLine (const std::string &line)
 
void advanceLine (const int nline=1)
 
void advanceCursor (const std::string &token)
 
int yyinput (char *buffer, const int max_size)
 

Static Public Member Functions

static ParsergetParser ()
 

Private Member Functions

 Parser (const Parser &)
 
void operator= (const Parser &)
 

Private Attributes

int d_errors
 
int d_warnings
 
List< Parser::ParseDatad_parse_stack
 
List< Pointer< Database > > d_scope_stack
 
std::string d_pathname
 

Static Private Attributes

static Parsers_default_parser
 
static bool s_static_tables_initialized
 

Detailed Description

Class Parser parses the user input file and places the resulting (key,value) pairs into the input database object. The parser object controls the overall parsing of the input file, which includes error handing and tracking file, line number, and cursor position. If running on multiple processors, only node zero reads in data from the specified input file and broadcasts that data to the other processors. The input file argument for the other processors is ignored and may be NULL.

The parser class also defines a `‘default’' parser that may be accessed via a static member function. The default parser may only be accessed by the yacc/lex routines called during the input file parsing. This singleton-like approach provides a clean way to communicate parser information to the yacc/lex files without global variables.

This parser (and the associated yacc and lex files) assume the GNU flex and bison utilities. These utilities are only required if the grammar or scanner is changed, since the SAMRAI distribution already contains the output files from flex and bison.

Constructor & Destructor Documentation

◆ Parser() [1/2]

SAMRAI::tbox::Parser::Parser ( )

The parser constructor simply creates an uninitialized parser object. Member function parse() must be called before any other member function to initialize the object and parse the input data. Function parse() may be called multiple times to parse multiple input files, but all state values (such as the number of errors or warnings) are reset at the beginning of each new parse pass.

◆ ~Parser()

SAMRAI::tbox::Parser::~Parser ( )

Destroy the parser object and deallocate parser data.

◆ Parser() [2/2]

SAMRAI::tbox::Parser::Parser ( const Parser )
private

Member Function Documentation

◆ parse()

int SAMRAI::tbox::Parser::parse ( const std::string &  filename,
FILE *  fstream,
Pointer< Database database 
)

Parse the input file from the specified file stream. The number of syntax errors is returned. A successful parse will return zero errors. The parse() function takes the initial filename (for informational purposes) and the filestream from which to read the parse data. All (key,value) pairs are placed in the specified database. If running in parallel, the fstream must be valid on node zero, but is ignored on other nodes and may be set to NULL. Multiple input files may be parsed by calling parse() for each file, but all variables are reset at the beginning of each parse.

◆ getNumberErrors()

int SAMRAI::tbox::Parser::getNumberErrors ( ) const

Return the total number of errors resulting from the parse.

◆ getNumberWarnings()

int SAMRAI::tbox::Parser::getNumberWarnings ( ) const

Return the total number of warnings resulting from the parse.

◆ getParser()

static Parser* SAMRAI::tbox::Parser::getParser ( )
static

Return the parser object. This mechanism is useful for communicating with the yacc/lex routines during the input file parse. The default parser will be NULL outside of the parse call.

◆ getScope()

Pointer<Database>& SAMRAI::tbox::Parser::getScope ( )

Return the current database scope. The current scope is modified through the enterScope() and leaveScope() member functions.

◆ enterScope()

void SAMRAI::tbox::Parser::enterScope ( const std::string &  name)

Create a new database scope with the specified name. This new scope will be the default scope until leaveScope() is called.

◆ leaveScope()

void SAMRAI::tbox::Parser::leaveScope ( )

Leave the current database scope and return to the previous scope. It is an error to leave the outermost scope.

◆ getDatabaseWithKey()

Pointer<Database> SAMRAI::tbox::Parser::getDatabaseWithKey ( const std::string &  name)

Lookup the scope that contains the specified key. If the scope does not exist, then return a NULL pointer to the database.

◆ pushIncludeFile()

bool SAMRAI::tbox::Parser::pushIncludeFile ( const std::string &  filename)

Save the current context and switch to the specified input file. This routine returns true if the file exists and the switch was successful and false otherwise.

◆ popIncludeFile()

void SAMRAI::tbox::Parser::popIncludeFile ( )

Pop the include file context off of the stack and return to the previous include file.

◆ error()

void SAMRAI::tbox::Parser::error ( const std::string &  message)

Report a parsing error with the specified error message. This routine will only be called from the parser or the scanner. Errors are printed to pout, since it is assumed that all nodes are parsing the same input file.

◆ warning()

void SAMRAI::tbox::Parser::warning ( const std::string &  message)

Report a parsing warning with the specified warning message. This routine will only be called from the parser or the scanner. Errors are printed to pout, since it is assumed that all nodes are parsing the same input file.

◆ setLine()

void SAMRAI::tbox::Parser::setLine ( const std::string &  line)

Set the input line which is currently being parsed.

◆ advanceLine()

void SAMRAI::tbox::Parser::advanceLine ( const int  nline = 1)

Advance the line number by the specified number of lines. If no argument is given, then the line number is advanced by one line.

◆ advanceCursor()

void SAMRAI::tbox::Parser::advanceCursor ( const std::string &  token)

Advance the position of the cursor on the line using the values in the specified character string. Tab characters in the string are assumed to advance the cursor to eight character tab stops. The cursor position is automatically reset to one whenever the line number is changed.

◆ yyinput()

int SAMRAI::tbox::Parser::yyinput ( char *  buffer,
const int  max_size 
)

Define the input reading routine used by flex. Under MPI, node zero reads the input and broadcasts the character data to all processors.

◆ operator=()

void SAMRAI::tbox::Parser::operator= ( const Parser )
private

Member Data Documentation

◆ d_errors

int SAMRAI::tbox::Parser::d_errors
private

◆ d_warnings

int SAMRAI::tbox::Parser::d_warnings
private

◆ d_parse_stack

List< Parser::ParseData > SAMRAI::tbox::Parser::d_parse_stack
private

◆ d_scope_stack

List< Pointer< Database > > SAMRAI::tbox::Parser::d_scope_stack
private

◆ s_default_parser

Parser* SAMRAI::tbox::Parser::s_default_parser
staticprivate

◆ s_static_tables_initialized

bool SAMRAI::tbox::Parser::s_static_tables_initialized
staticprivate

◆ d_pathname

std::string SAMRAI::tbox::Parser::d_pathname
private

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