Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

SAMRAI::tbox::Parser Class Reference

#include <source/toolbox/inputdb/Parser.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

static ParsergetParser ()


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

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.

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

Destroy the parser object and deallocate parser data.


Member Function Documentation

int SAMRAI::tbox::Parser::parse const 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.

int SAMRAI::tbox::Parser::getNumberErrors  )  const [inline]
 

Return the total number of errors resulting from the parse.

int SAMRAI::tbox::Parser::getNumberWarnings  )  const [inline]
 

Return the total number of warnings resulting from the parse.

Parser * SAMRAI::tbox::Parser::getParser  )  [inline, 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.

Pointer< Database > & SAMRAI::tbox::Parser::getScope  )  [inline]
 

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

void SAMRAI::tbox::Parser::enterScope const string &  name  )  [inline]
 

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

void SAMRAI::tbox::Parser::leaveScope  )  [inline]
 

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

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

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

bool SAMRAI::tbox::Parser::pushIncludeFile const 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.

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

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

void SAMRAI::tbox::Parser::error const 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.

void SAMRAI::tbox::Parser::warning const 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.

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

Set the input line which is currently being parsed.

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.

void SAMRAI::tbox::Parser::advanceCursor const 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.

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.


The documentation for this class was generated from the following files:
Generated on Fri Dec 2 11:33:19 2005 for SAMRAI by  doxygen 1.4.2