| LLOOP Index | GSP Language | GSP Library | Framework Classes | Component Classes |
#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...
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 | ( ) | ||
| destroyRoot | ( ) | |
| getConstByIndex | ( unsigned long u ) const | |
| getExternalSymbolByIndex | ( unsigned long u ) const | |
| getNonTerminalByIndex | ( unsigned long u ) const | |
| getTokenByIndex | ( unsigned long u ) const | |
| root | ( ) | |
| testSymbols | ( std::ostream & os , bool bVerbose = false ) | |
Protected Functions | |||
| checkSymbolsOccurrences | ( ) | |
| initialize | ( ) | |
| parse | ( ) | |
| preprocess | ( char & c ) | |
| writeStats | ( ) | |
Private Functions | |||
| sortSymbols | ( ) | |
| symbolsSorted | ( ) const | |
Public Static Functions | |||
| createSymbol | ( const char * pszSymbolName ) | ||
| destroySymbol | ( gsp::Symbol * & pSymbol ) | |
Private Variables | |||
| m_bSymbolsSorted | ||
| m_ini_comment | |||
| m_pAllBlockTokens | |||
| m_pAllDataLists | |||
| m_pAllIdTokens | |||
| m_pAllSectionLists | |||
| m_pAll_ConstChoice_0s | |||
| m_pRootSymbol | ||
Public Static Variables | |||
| CONSTANTS [ ] | ||
| EXTERNAL_SYMBOLS [ ] | ||
| NON_TERMINALS [ ] | ||
| TOKENS [ ] | ||
Private Types | |||
| |||
Friends | |||
| gsp::Symbol | ||
| SymbolSorter | ||
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.
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:
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:
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:
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:
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:
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:
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:
Initializes the parser object, setting appropriate default status.
Private.
See also:
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:
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:
Self-explanatory.
See also:
Self-explanatory.
See also:
Self-explanatory.
See also:
Self-explanatory.
See also:
Self-explanatory.
See also:
Returns the constant of the specified index.
If the index is out of range, an empty string is returned.
See also:
Returns the token of the specified index.
If the index is out of range, an empty string is returned.
See also:
Returns the non-terminal of the specified index.
If the index is out of range, an empty string is returned.
See also:
Returns the external symbol of the specified index.
If the index is out of range, an empty string is returned.
See also:
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:
Runs the parsing.
Creates the root symbol object if it was not created it.
This method is internally called by run().
Private.
See also:
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:
Checks whether the number of instances parsed for each symbol is consistent with the occurrence constraints defined for it in the grammar.
See also:
Writes the parse statistics file.
At the moment, it just reports the number of instances created for each symbol class.
Private.
See also:
Tells whether all the symbols parsed have already been sorted by their type.
See also:
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:
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 |