| Index |
Symbol visitor class. More...
#include "gsp__Visitor.h"
Symbol visitor class.
The use of the visitor design patter is useful to scan through the parsed symbols tree in the same order as they were parsed.
The field of use of the visitor pattern is wide. It can be used for implementing any post-processors after the parsing, e.g. to perform some checks on structured language can only be done once the whole context of some data has been parsed, as checking that a used variable or function was declared. It could also be used for automatic code correction or perform any other advanced substitution of a subset data in a complex structured stream.
For a symbol to be visited, its visit() method must be called with the visitor object as argument. The 'process' function of the visitor is called there with a pointer to the symbol as argument. The right-hand symbols of the parsed rule are in turn made visited.
Visitor constructor.
See also:
Visitor destructor.
See also:
Performs the visitor's actions for the passed symbol rpSymbol. This is called by the symbol itself from its generated visit() method.
The visitor has the possibility to change the passed pointer to another one pointing to a replacement symbol object for the one pointed to by rpSymbol in the hierarchy of parsed object.
Returns a boolean telling whether the processing was successful.
See also:
Performs the visitor's actions for the passed constant c_pszConstant. This method is called by the parent symbol itself from its generated visit() method. The first argument c_pszConstant gives the value of the constant; the second is a reference to the parent symbol, and at last the third argument uSymbolRank gives the symbol rank of the constant in the rule reduced for the parent symbol.
Returns a boolean telling whether the processing was successful.
See also:
If the symbol is a non-terminal, it does nothing and true is returned. If the symbol is a token, it prints out the value of the token as it was parsed in the original input stream.
Returns true if the operation was successful, which is normally always the case if the expanded symbol was initially parsed successfully.
The code executed is the following:
Example:
if (rpSymbol)
{
if (rpSymbol->isToken())
{
rpSymbol->restore_ws(0, m_os);
rpSymbol->expand(m_os);
}
else // (rpSymbol->isNonTerminal())
{
// Nothing to do
}
return true;
}
else
{
return false;
}See also:
Prints out the value of the passed constant, restituting the preceding whitespaces that were eaten during parsing.
Returns always true.
The code executed is the following:
Example:
parent.restore_ws(uSymbolRank, m_os); m_os << c_pszConstant; return true;
See also:
If the symbol is a non-terminal, prints out its name followed by the BNF description of the reduced rule for this symbol. Only the names of the reduced rule's right-hand symbols are shown. The meta-symbols [ ] and the { } are not shown.
If the symbol is a token, prints out its name followed by its value as it was parsed in the original input stream.
Returns true if the operation was successful, which is normally always the case if the backtraced symbol was initially parsed successfully.
The code executed is the following:
Example:
if (rpSymbol)
{
if (rpSymbol->isToken())
{
rpSymbol->backtrace(m_os);
}
else // (rpSymbol->isNonTerminal())
{
if (rpSymbol != rpSymbol->getParent())
{
gsp::Symbol* pParent = rpSymbol->getParent();
gsp::Symbol* pPrevParent = NULL;
while (pParent != pPrevParent)
{
m_os << " ";
pPrevParent = pParent;
pParent = pParent->getParent();
}
m_os << "|__ ";
}
m_os << rpSymbol->getSymbolName();
m_os << " => ";
rpSymbol->outputReducedRule(m_os);
m_os << "\n";
}
return true;
}
else
{
return false;
}See also:
Constants are not shown during backtracing. They are already shown when the reduced rule is printed out for a backtraced non-terminal.
Returns always true.
The code executed is the following:
Example:
return true;
See also: