Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Public Member Functions | Friends
grammar::CSG< SymbolType > Class Template Referencefinal

Context sensitive grammar in Chomsky hierarchy or type 1 in Chomsky hierarchy. Generates context sensitive languages. More...

#include <CSG.h>

Inheritance diagram for grammar::CSG< SymbolType >:
[legend]
Collaboration diagram for grammar::CSG< SymbolType >:
[legend]

Public Member Functions

 CSG (SymbolType initialSymbol)
 Creates a new instance of the grammar with a concrete initial symbol. More...
 
 CSG (ext::set< SymbolType > nonterminalAlphabet, ext::set< SymbolType > terminalAlphabet, SymbolType initialSymbol)
 Creates a new instance of the grammar with a concrete nonterminal alphabet, terminal alphabet and initial symbol. More...
 
bool addRule (ext::vector< SymbolType > lContext, SymbolType leftHandSide, ext::vector< SymbolType > rContext, ext::vector< SymbolType > rightHandSide)
 Add a new rule of a grammar. More...
 
void addRules (ext::vector< SymbolType > lContext, SymbolType leftHandSide, ext::vector< SymbolType > rContext, ext::set< ext::vector< SymbolType > > rightHandSide)
 Add new rules of a grammar. More...
 
const ext::map< ext::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > & getRules () const &
 
ext::map< ext::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > && getRules () &&
 
bool removeRule (const ext::vector< SymbolType > &lContext, const SymbolType &leftHandSide, const ext::vector< SymbolType > &rContext, const ext::vector< SymbolType > &rightHandSide)
 
const SymbolType & getInitialSymbol () const &
 
SymbolType && getInitialSymbol () &&
 
bool setInitialSymbol (SymbolType symbol)
 
const ext::set< SymbolType > & getNonterminalAlphabet () const &
 
ext::set< SymbolType > && getNonterminalAlphabet () &&
 
bool addNonterminalSymbol (SymbolType symbol)
 
void setNonterminalAlphabet (ext::set< SymbolType > symbols)
 
const ext::set< SymbolType > & getTerminalAlphabet () const &
 
ext::set< SymbolType > && getTerminalAlphabet () &&
 
bool addTerminalSymbol (SymbolType symbol)
 
void setTerminalAlphabet (ext::set< SymbolType > symbols)
 
void setGeneratesEpsilon (bool genEps)
 
bool getGeneratesEpsilon () const
 
auto operator<=> (const CSG &other) const
 
bool operator== (const CSG &other) const
 
- Public Member Functions inherited from core::Components< CSG< DefaultSymbolType >, ext::set< DefaultSymbolType >, component::Set, std::tuple< TerminalAlphabet, NonterminalAlphabet >, DefaultSymbolType, component::Value, InitialSymbol >
void accessComponent ()
 

Friends

ext::ostreamoperator<< (ext::ostream &out, const CSG &instance)
 

Additional Inherited Members

- Static Public Member Functions inherited from core::Components< CSG< DefaultSymbolType >, ext::set< DefaultSymbolType >, component::Set, std::tuple< TerminalAlphabet, NonterminalAlphabet >, DefaultSymbolType, component::Value, InitialSymbol >
static void registerComponent ()
 
static void unregisterComponent ()
 

Detailed Description

template<class SymbolType = DefaultSymbolType>
class grammar::CSG< SymbolType >

Context sensitive grammar in Chomsky hierarchy or type 1 in Chomsky hierarchy. Generates context sensitive languages.

Definition is similar to all common definitions of context sensitive grammars. G = (N, T, P, S), N (NonterminalAlphabet) = nonempty finite set of nonterminal symbols, T (TerminalAlphabet) = finite set of terminal symbols - having this empty won't let grammar do much though, P = set of production rules of the form \alpha A \beta -> \alpha B \beta, where A \in N, B \in ( N \cup T )+ and \alpha, \beta \in ( N \cup T )*, S (InitialSymbol) = initial nonterminal symbol,

Template Parameters
SymbolTypeused for the terminal alphabet, the nonterminal alphabet, and the initial symbol of the grammar.

Constructor & Destructor Documentation

◆ CSG() [1/2]

template<class SymbolType >
grammar::CSG< SymbolType >::CSG ( SymbolType  initialSymbol)
explicit

Creates a new instance of the grammar with a concrete initial symbol.

Parameters
initialSymbolthe initial symbol of the grammar

◆ CSG() [2/2]

template<class SymbolType >
grammar::CSG< SymbolType >::CSG ( ext::set< SymbolType >  nonterminalAlphabet,
ext::set< SymbolType >  terminalAlphabet,
SymbolType  initialSymbol 
)
explicit

Creates a new instance of the grammar with a concrete nonterminal alphabet, terminal alphabet and initial symbol.

Parameters
nonTerminalSymbolsthe initial nonterminal alphabet
terminalSymbolsthe initial terminal alphabet
initialSymbolthe initial symbol of the grammar

Member Function Documentation

◆ addNonterminalSymbol()

template<class SymbolType = DefaultSymbolType>
bool grammar::CSG< SymbolType >::addNonterminalSymbol ( SymbolType  symbol)
inline

Adder of nonterminal symbol.

Parameters
symbolthe new symbol to be added to nonterminal alphabet
Returns
true if the symbol was indeed added

◆ addRule()

template<class SymbolType >
bool grammar::CSG< SymbolType >::addRule ( ext::vector< SymbolType >  lContext,
SymbolType  leftHandSide,
ext::vector< SymbolType >  rContext,
ext::vector< SymbolType >  rightHandSide 
)

Add a new rule of a grammar.

The rule is in a form of \alpha A \beta -> \alpha B \beta, where A \in N, B \in ( N \cup T )+, and \alpha, \beta \in ( N \cup T )*.

Parameters
lContextthe left context of the rule
leftHandSidethe left hand side of the rule
rContextthe right context of the rule
rightHandSidethe right hand side of the rule
Returns
true if the rule was indeed added, false othervise
Here is the call graph for this function:

◆ addRules()

template<class SymbolType >
void grammar::CSG< SymbolType >::addRules ( ext::vector< SymbolType >  lContext,
SymbolType  leftHandSide,
ext::vector< SymbolType >  rContext,
ext::set< ext::vector< SymbolType > >  rightHandSide 
)

Add new rules of a grammar.

The rules are in form of \alpha A \beta -> \alpha B \beta | \alpha C \beta | ..., where A \in N, B, C ... \in ( N \cup T )+, and \alpha, \beta \in ( N \cup T )*.

Parameters
lContextthe left context of the rule
leftHandSidethe left hand side of the rule
rContextthe right context of the rule
rightHandSidea set of right hand sides of the rule
Here is the call graph for this function:

◆ addTerminalSymbol()

template<class SymbolType = DefaultSymbolType>
bool grammar::CSG< SymbolType >::addTerminalSymbol ( SymbolType  symbol)
inline

Adder of terminal symbol.

Parameters
symbolthe new symbol tuo be added to nonterminal alphabet
Returns
true if the symbol was indeed added

◆ getGeneratesEpsilon()

template<class SymbolType >
bool grammar::CSG< SymbolType >::getGeneratesEpsilon

Gets sign representing that grammar generates or doesn't generate empty word.

Returns
sign representing the posibility of generating empty string from the grammar

◆ getInitialSymbol() [1/2]

template<class SymbolType = DefaultSymbolType>
SymbolType && grammar::CSG< SymbolType >::getInitialSymbol ( ) &&
inline

Getter of initial symbol.

Returns
the initial symbol of the grammar
Here is the call graph for this function:

◆ getInitialSymbol() [2/2]

template<class SymbolType = DefaultSymbolType>
const SymbolType & grammar::CSG< SymbolType >::getInitialSymbol ( ) const &
inline

Getter of initial symbol.

Returns
the initial symbol of the grammar
Here is the caller graph for this function:

◆ getNonterminalAlphabet() [1/2]

template<class SymbolType = DefaultSymbolType>
ext::set< SymbolType > && grammar::CSG< SymbolType >::getNonterminalAlphabet ( ) &&
inline

Getter of nonterminal alphabet.

Returns
the nonterminal alphabet of the grammar
Here is the call graph for this function:

◆ getNonterminalAlphabet() [2/2]

template<class SymbolType = DefaultSymbolType>
const ext::set< SymbolType > & grammar::CSG< SymbolType >::getNonterminalAlphabet ( ) const &
inline

Getter of nonterminal alphabet.

Returns
the nonterminal alphabet of the grammar
Here is the caller graph for this function:

◆ getRules() [1/2]

template<class SymbolType = DefaultSymbolType>
ext::map< ext::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > && grammar::CSG< SymbolType >::getRules ( ) &&

Get rules of the grammar.

Returns
rules of the grammar

◆ getRules() [2/2]

template<class SymbolType = DefaultSymbolType>
const ext::map< ext::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > & grammar::CSG< SymbolType >::getRules ( ) const &

Get rules of the grammar.

Returns
rules of the grammar
Here is the caller graph for this function:

◆ getTerminalAlphabet() [1/2]

template<class SymbolType = DefaultSymbolType>
ext::set< SymbolType > && grammar::CSG< SymbolType >::getTerminalAlphabet ( ) &&
inline

Getter of terminal alphabet.

Returns
the terminal alphabet of the grammar
Here is the call graph for this function:

◆ getTerminalAlphabet() [2/2]

template<class SymbolType = DefaultSymbolType>
const ext::set< SymbolType > & grammar::CSG< SymbolType >::getTerminalAlphabet ( ) const &
inline

Getter of terminal alphabet.

Returns
the terminal alphabet of the grammar
Here is the caller graph for this function:

◆ operator<=>()

template<class SymbolType = DefaultSymbolType>
auto grammar::CSG< SymbolType >::operator<=> ( const CSG< SymbolType > &  other) const
inline

The three way comparison implementation

Parameters
otherthe other instance
Returns
the ordering between this object and the other.
Here is the call graph for this function:

◆ operator==()

template<class SymbolType = DefaultSymbolType>
bool grammar::CSG< SymbolType >::operator== ( const CSG< SymbolType > &  other) const
inline

The equality comparison implementation.

Parameters
otherthe other object to compare with.
Returns
true if this and other objects are equal, false othervise
Here is the call graph for this function:

◆ removeRule()

template<class SymbolType >
bool grammar::CSG< SymbolType >::removeRule ( const ext::vector< SymbolType > &  lContext,
const SymbolType &  leftHandSide,
const ext::vector< SymbolType > &  rContext,
const ext::vector< SymbolType > &  rightHandSide 
)

Remove a rule of a grammar in form of \alpha A \beta -> \alpha B \beta, where A \in N, B \in (N \cup T)+, and \alpha, \beta \in ( N \cup T )*.

Parameters
lContextthe left context of the rule
leftHandSidethe left hand side of the rule
rContextthe right context of the rule
rightHandSidethe right hand side of the rule
Returns
true if the rule was indeed removed, false othervise
Here is the call graph for this function:

◆ setGeneratesEpsilon()

template<class SymbolType >
void grammar::CSG< SymbolType >::setGeneratesEpsilon ( bool  genEps)

Sets sign representing that grammar generates or doesn't generate empty word.

Parameters
genEpssign representing the posibility of generating empty string from the grammar

◆ setInitialSymbol()

template<class SymbolType = DefaultSymbolType>
bool grammar::CSG< SymbolType >::setInitialSymbol ( SymbolType  symbol)
inline

Setter of initial symbol.

Parameters
symbolnew initial symbol of the grammar
Returns
true if the initial symbol was indeed changed

◆ setNonterminalAlphabet()

template<class SymbolType = DefaultSymbolType>
void grammar::CSG< SymbolType >::setNonterminalAlphabet ( ext::set< SymbolType >  symbols)
inline

Setter of nonterminal alphabet.

Parameters
symbolscompletely new nonterminal alphabet

◆ setTerminalAlphabet()

template<class SymbolType = DefaultSymbolType>
void grammar::CSG< SymbolType >::setTerminalAlphabet ( ext::set< SymbolType >  symbols)
inline

Setter of terminal alphabet.

Parameters
symbolcompletely new nontemrinal alphabet

Friends And Related Function Documentation

◆ operator<<

template<class SymbolType = DefaultSymbolType>
ext::ostream & operator<< ( ext::ostream out,
const CSG< SymbolType > &  instance 
)
friend

Print this object as raw representation to ostream.

Parameters
outostream where to print
instanceobject to print
Returns
modified output stream

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