LLOOP Index | GSP Language | GSP Library | Framework Classes | Component Classes

Parser Class Reference

#include "ini__Parser.h"

This is the end-user parser class to be used to parse input streams according to the grammar from which this parser was generated. More...


Inherited Class(es)


Public Functions

Parser ( std::istream & is 
Parser ( const char * pszFilename 
Parser ( int argc , char * * argv , const char * pszLeftValDelim = "\"" , const char * pszRightValDelim = "\"" ) 
Parser ( int fd 
~Parser ( ) 
allBlockTokens ( ) 
allDataLists ( ) 
allIdTokens ( ) 
allSectionLists ( ) 
all_ConstChoice_0s ( ) 
  • void 
destroyRoot ( ) 
  • const char * 
getConstByIndex ( unsigned long ) const 
  • const char * 
getExternalSymbolByIndex ( unsigned long ) const 
  • const char * 
getNonTerminalByIndex ( unsigned long ) const 
  • const char * 
getTokenByIndex ( unsigned long ) const 
root ( ) 
  • bool 
testSymbols ( std::ostream & os , bool bVerbose = false ) 

Protected Functions

  • bool 
checkSymbolsOccurrences ( ) 
  • void 
initialize ( ) 
  • bool 
parse ( ) 
  • bool 
preprocess ( char & 
  • void 
writeStats ( ) 

Private Functions

  • void 
sortSymbols ( ) 
  • bool 
symbolsSorted ( ) const 

Public Static Functions

createSymbol ( const char * pszSymbolName 
  • void 
destroySymbol gsp::Symbol * & pSymbol 

Private Variables

  • bool 
m_bSymbolsSorted 
m_ini_comment 
m_pAllBlockTokens 
m_pAllDataLists 
m_pAllIdTokens 
m_pAllSectionLists 
m_pAll_ConstChoice_0s 
m_pRootSymbol 

Public Static Variables

  • char * 
CONSTANTS [  ] 
  • char * 
EXTERNAL_SYMBOLS [  ] 
  • char * 
NON_TERMINALS [  ] 
  • char * 
TOKENS [  ] 

Private Types

Friends

  • class 
gsp::Symbol 
  • class 
SymbolSorter 

Detailed Description

This is the end-user parser class to be used to parse input streams according to the grammar from which this parser was generated.

Using a parser is straightforward. It just consists in passing to the appropriate constructor the source from which to get the char stream, running the parsing with the run() method and getting results with other methods.

For further information and get any example of use, check the source of the examples provided with this documentation.


Files Included

#include <fstream>
#include <strstream>
#include "universal.h"
#include "universal__String.h"
#include <gsp__LLParser.h>
#include "gsp__Visitor.h"
#include "ini__ini_comment.h"

Functions Documentation

gsp::Symbol * createSymbol ( const char * pszSymbolName   [  static  ] 

Symbol Class Factory method. Creates an instance of a symbol class (either token or non-terminal class) from its name. For the object instantiation, this method relies itself on the factory object of the respective symbol class.

Returns NULL if the passed name is not a valid symbol name.

Note:

The generated parse code does not rely on this method for symbol class instantiations due to its relative inefficiency (string comparisons). It was initially foreseen as a facility means for the end-user.

Example:

 ...
 using namespace sample;
 ...
 SampleToken *p = Parser::createSymbol("SampleToken");    // p != NULL
 SampleToken *p2 = Parser::createSymbol("InvalidSymbol"); // p2 == NULL
 ...

See also:

virtual SampleNonTerminal * SampleNonTerminalFactory::create ( ) 
static void destroySymbol gsp::Symbol * & pSymbol 
Back to index

void destroySymbol gsp::Symbol * & pSymbol   [  static  ] 

Symbol Class Factory method. Destroys an instance previously obtained using the above createSymbol() factory method and sets the passed pointer to NULL. For the object destruction, this method relies itself on the factory object of the respective symbol class instance.

If the passed instance is not a valid symbol class instance, it raises a fatal parse error which results in a fatal parse failure interrupting the current parsing if there was any in progress.

Note:

The generated parse code does not rely on this method for symbol class destruction due to its relative inefficiency (string comparisons). It was initially foreseen as a facility means for the end-user.

Example:

 ...
 using namespace sample;
 ...
 SampleToken *p = Parser::createSymbol("SampleToken");    // p != NULL
 ...
 parser.destroySymbol(p); // p == NULL
 ...

See also:

virtual SampleNonTerminal * SampleNonTerminalFactory::destroy ( ) 
static gsp::Symbol * createSymbol ( const char * pszSymbolName 
Back to index

Parser ( std::istream & is 

Constructs a parser that will read the input chars from the passed is input stream reference, regardless of the actual type of the input stream, e.g. a file stream (fstream) or a string stream (strstream).

Default parser status is:

- Stream break-off is expected when parsing is completed.

- root() raises an exception as no root symbol is still created.

- done() returns false (parsing not done yet).

- fail() returns false (no failure).

- getLineNo() returns 1.

- nbErrors() returns 0.

- syntaxerror() returns false (no syntax error).

- ignoreCase() returns true if the parse code was generated with the '--ignore-case' option. False otherwise.

- showLineNo() returns true, i.e. the line numbers are shown in the error contexts.

Example:

 #include <fstream>
 ...
 ifstream ifs("myfile");
 sample::Parser parser(ifs);
 parser.run();
 if (parser.fail())
 {
   // Handle error here.
 }

Example:

 #include <strstream>
 ...
 strstream str;
 str << "line, 1, 2.0: , , a constant";
 sample::Parser parser(str);
 parser.run();
 if (parser.fail())
 {
   // Handle error here.
 }

See also:

Parser ( int fd 
Parser ( const char * pszFilename 
Parser ( int argc , char * * argv , const char * pszLeftValDelim = "\"" , const char * pszRightValDelim = "\"" ) 
void LLParser::endWithStreamBreakOff ( bool bBreakOff = true ) 
bool LLParser::done ( ) const 
bool LLParser::fail ( ) const 
bool LLParser::ignoreCase ( ) const 
unsigned int LLParser::getLineNo ( ) const 
unsigned long LLParser::nbErrors ( ) const 
bool LLParser::syntaxerror ( ) const 
Back to index

Parser ( int ifd 

This is an overloaded constructor provided for convenience. It behaves essentially like the above constructor.

Constructs a parser that will get the input chars from the passed ifd file descriptor, regardless of the actual type of the file, e.g. a conventional system file, a socket or whatever else for which a file descriptor can be got.

Example:

 #include <fstream>
 ...
 int ifd = open("myfile", O_RDONLY);
 sample::Parser parser(ifd);
 parser.run();
 if (parser.fail())
 {
   // Handle error here.
 }

See also:

Parser ( std::istream & is 
Parser ( const char * pszFilename 
Back to index

Parser ( const char * pszFilename 

This is an overloaded constructor provided for convenience. It behaves essentially like the above constructor.

Constructs a parser that will get the input chars from the passed file name or file path.

If the file couldn't be opened, fail() will return true and an error message is returned by getFailureMessage().

Example:

   sample::Parser parser("my_file");

is equivalent to

Example:

   ifstream ifs("my_file");
   sample::Parser parser(ifs);

See also:

Parser ( std::istream & is 
const universal::String & LLParser::getFailureMessage ( ) const 
void LLParser::outputFailureMessage ( std::ostream & os ) const 
bool LLParser::fail ( ) const 
Back to index

Parser ( int argc , char * * argv , const char * pszLeftValDelim , const char * pszRightValDelim 

This is an overloaded constructor provided for convenience. It behaves essentially like the above constructor.

Constructs a parser that will get the input chars from the passed arguments argc and argv which are typically those passed to the main() function of a program.

Argument values containing relevant whitespaces are surrounded with left delimiter pszLeftValDelim and right delimiter pszRightValDelim (by default double quotes in both cases) to avoid parse problems when values contain relevant whitespaces.

Example:

   sample::Parser parser(argc, argv);

is equivalent to

Example:

  strstream str;
  universal::String sArg;
  for (i=1; i < argc; i++)
    {
      sArg = argv[i];
      if ((sArg.indexOf(' ') >= 0) ||
	  (sArg.indexOf('\t') >= 0) ||
	  (sArg.indexOf('\v') >= 0) ||
	  (sArg.indexOf('\r') >= 0) ||
	  (sArg.indexOf('\f') >= 0)
	  )
	{
	  str << pszLeftValDelim << sArg.str() << pszRightValDelim << " ";
	}
      else
	{
	  str << sArg.str() << " ";
	}
    }
   str << ends;
   sample::Parser parser(str);

Note: When a parser is constructed with this constructor, no line number is shown in failure contexts.

See also:

Parser ( std::istream & is 
universal::String LLParser::getFailureContext ( unsigned long uNbLinesAround = 1 ) 
Back to index

~Parser ( )   [  virtual  ] 

Destructor.

Note:

The root symbol object that was possibly instantiated when the last parsing was run is NOT destroyed. It is up to calling programs to manage root objects destruction following parse runs.

See also:

Parser ( std::istream & is 
Parser ( int fd 
Parser ( const char * pszFilename 
Parser ( int argc , char * * argv , const char * pszLeftValDelim = "\"" , const char * pszRightValDelim = "\"" ) 
Back to index

void initialize ( )   [  protected  ]   [  virtual  ] 

Initializes the parser object, setting appropriate default status.

Private.

See also:

Parser ( std::istream & is 
Back to index

SIniFile & root ( ) 

Returns a reference to the root object.

Creates the root object if the it was not created yet (the parsing was not run yet) or if it was already destroyed with destroyRoot().

When destroyRoot() is not called, it is up to calling programs to manage root objects destruction.

See also:

void destroyRoot ( ) 
void LLParser::run ( ) 
Back to index

void destroyRoot ( ) 

Destroys the root object.

Following this call, any reference to the root object obtained with root() becomes invalid and a subsequent call to root() returns a new object.

When destroyRoot() is not called, it is up to calling programs to manage root objects destruction.

See also:

SIniFile & root ( ) 
Back to index

_ConstChoice_0Composite & all_ConstChoice_0s ( ) 

Self-explanatory.

See also:

Back to index

SectionListComposite & allSectionLists ( ) 

Self-explanatory.

See also:

Back to index

DataListComposite & allDataLists ( ) 

Self-explanatory.

See also:

Back to index

IdTokenComposite & allIdTokens ( ) 

Self-explanatory.

See also:

Back to index

BlockTokenComposite & allBlockTokens ( ) 

Self-explanatory.

See also:

Back to index

const char * getConstByIndex ( unsigned long ) const   [  virtual  ] 

Returns the constant of the specified index.

If the index is out of range, an empty string is returned.

See also:

Back to index

const char * getTokenByIndex ( unsigned long ) const   [  virtual  ] 

Returns the token of the specified index.

If the index is out of range, an empty string is returned.

See also:

Back to index

const char * getNonTerminalByIndex ( unsigned long ) const   [  virtual  ] 

Returns the non-terminal of the specified index.

If the index is out of range, an empty string is returned.

See also:

Back to index

const char * getExternalSymbolByIndex ( unsigned long ) const   [  virtual  ] 

Returns the external symbol of the specified index.

If the index is out of range, an empty string is returned.

See also:

Back to index

bool testSymbols ( std::ostream & os , bool bVerbose   [  virtual  ] 

Runs all the tests defined for the symbols imported or defined in the grammar.

Returns false if at least one test failed.

Tests outputs and results are printed out into the passed output stream os.

bVerbose tells whether to print out additional information about the run tests. bVerbose is optional and is not set by default. This value is forwarded to the respective test() method called on each tested symbol.

See also:

virtual bool LLParser::testSymbols ( std::ostream & os , bool bVerbose = false ) = 0 
Back to index

bool parse ( )   [  protected  ]   [  virtual  ] 

Runs the parsing.

Creates the root symbol object if it was not created it.

This method is internally called by run().

Private.

See also:

bool LLParser::done ( ) const 
void LLParser::run ( ) 
Back to index

bool preprocess ( char &   [  protected  ]   [  virtual  ] 

Pre-processes c. This function should return false if the character has to be excluded from the stream that will be parsed. The value of c may be replaced with another by the pre-processing routines.

Private.

See also:

bool LLParser::preprocess ( ) 
Back to index

bool checkSymbolsOccurrences ( )   [  protected  ]   [  virtual  ] 

Checks whether the number of instances parsed for each symbol is consistent with the occurrence constraints defined for it in the grammar.

See also:

void LLParser::deactivateSymbolsOccurrencesCheck ( bool bYes = true ) 
bool LLParser::isSymbolsOccurrencesCheckDeactivated ( ) const 
Back to index

void writeStats ( )   [  protected  ]   [  virtual  ] 

Writes the parse statistics file.

At the moment, it just reports the number of instances created for each symbol class.

Private.

See also:

Back to index

bool symbolsSorted ( ) const   [  private  ] 

Tells whether all the symbols parsed have already been sorted by their type.

See also:

void sortSymbols ( ) 
Back to index

void sortSymbols ( )   [  private  ] 

Sorts the symbols by their type. Every symbols of the same type are grouped a composite object which can got using the matching all..s() methods.

See also:

bool symbolsSorted ( ) const 
Back to index


This file is part of the LLOOP Reversible Object-Oriented Parser Generator. Copyright (c) 2005-2006 Michel MEHL, France. All rights reserved. LLOOP is distributed by the company ERSA SaRL.


Copyright (c) 2005-2006 Michel MEHL, Haguenau, France
LLOOP version 1.1


Generated with makedoc.