Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
|
Context preserving unrestricted grammar. Type 0 in Chomsky hierarchy. Generates recursively enumerable languages. More...
#include <ContextPreservingUnrestrictedGrammar.h>
Public Member Functions | |
ContextPreservingUnrestrictedGrammar (SymbolType initialSymbol) | |
Creates a new instance of the grammar with a concrete initial symbol. More... | |
ContextPreservingUnrestrictedGrammar (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) |
auto | operator<=> (const ContextPreservingUnrestrictedGrammar &other) const |
bool | operator== (const ContextPreservingUnrestrictedGrammar &other) const |
![]() | |
void | accessComponent () |
Friends | |
ext::ostream & | operator<< (ext::ostream &out, const ContextPreservingUnrestrictedGrammar &instance) |
Additional Inherited Members | |
![]() | |
static void | registerComponent () |
static void | unregisterComponent () |
Context preserving unrestricted grammar. Type 0 in Chomsky hierarchy. Generates recursively enumerable languages.
Definition is similar to all common definitions of unrestricted 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,
SymbolType | used for the terminal alphabet, the nonterminal alphabet, and the initial symbol of the grammar. |
|
explicit |
Creates a new instance of the grammar with a concrete initial symbol.
initialSymbol | the initial symbol of the grammar |
|
explicit |
Creates a new instance of the grammar with a concrete nonterminal alphabet, terminal alphabet and initial symbol.
nonTerminalSymbols | the initial nonterminal alphabet |
terminalSymbols | the initial terminal alphabet |
initialSymbol | the initial symbol of the grammar |
|
inline |
Adder of nonterminal symbol.
symbol | the new symbol to be added to nonterminal alphabet |
bool grammar::ContextPreservingUnrestrictedGrammar< 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 )*.
lContext | the left context of the rule |
leftHandSide | the left hand side of the rule |
rContext | the right context of the rule |
rightHandSide | the right hand side of the rule |
void grammar::ContextPreservingUnrestrictedGrammar< 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 )*.
lContext | the left context of the rule |
leftHandSide | the left hand side of the rule |
rContext | the right context of the rule |
rightHandSide | a set of right hand sides of the rule |
|
inline |
Adder of terminal symbol.
symbol | the new symbol tuo be added to nonterminal alphabet |
|
inline |
Getter of initial symbol.
|
inline |
Getter of initial symbol.
|
inline |
Getter of nonterminal alphabet.
|
inline |
Getter of nonterminal alphabet.
ext::map< ext::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > && grammar::ContextPreservingUnrestrictedGrammar< SymbolType >::getRules | ( | ) | && |
Get rules of the grammar.
const ext::map< ext::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > & grammar::ContextPreservingUnrestrictedGrammar< SymbolType >::getRules | ( | ) | const & |
Get rules of the grammar.
|
inline |
Getter of terminal alphabet.
|
inline |
Getter of terminal alphabet.
|
inline |
The three way comparison implementation
other | the other instance |
other
.
|
inline |
The equality comparison implementation.
other | the other object to compare with. |
bool grammar::ContextPreservingUnrestrictedGrammar< 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 )*.
lContext | the left context of the rule |
leftHandSide | the left hand side of the rule |
rContext | the right context of the rule |
rightHandSide | the right hand side of the rule |
|
inline |
Setter of initial symbol.
symbol | new initial symbol of the grammar |
|
inline |
Setter of nonterminal alphabet.
symbols | completely new nonterminal alphabet |
|
inline |
Setter of terminal alphabet.
symbol | completely new nontemrinal alphabet |
|
friend |
Print this object as raw representation to ostream.
out | ostream where to print |
instance | object to print |