Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
|
Noncontracting grammar in Chomsky hierarchy or type 1 in Chomsky hierarchy. Generates context sensitive languages. More...
#include <NonContractingGrammar.h>
Public Member Functions | |
NonContractingGrammar (SymbolType initialSymbol) | |
Creates a new instance of the grammar with a concrete initial symbol. More... | |
NonContractingGrammar (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 > leftHandSide, ext::vector< SymbolType > rightHandSide) |
Add a new rule of a grammar. More... | |
void | addRules (ext::vector< SymbolType > leftHandSide, ext::set< ext::vector< SymbolType > > rightHandSide) |
Add new rules of a grammar. More... | |
const ext::map< ext::vector< SymbolType >, ext::set< ext::vector< SymbolType > > > & | getRules () const & |
ext::map< ext::vector< SymbolType >, ext::set< ext::vector< SymbolType > > > && | getRules () && |
bool | removeRule (const ext::vector< SymbolType > &leftHandSide, 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 NonContractingGrammar &other) const |
bool | operator== (const NonContractingGrammar &other) const |
![]() | |
void | accessComponent () |
Friends | |
ext::ostream & | operator<< (ext::ostream &out, const NonContractingGrammar &instance) |
Additional Inherited Members | |
![]() | |
static void | registerComponent () |
static void | unregisterComponent () |
Noncontracting 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 A -> B, where A, B \in ( N \cup T )+ and |A| <= |B|, 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::NonContractingGrammar< SymbolType >::addRule | ( | ext::vector< SymbolType > | leftHandSide, |
ext::vector< SymbolType > | rightHandSide | ||
) |
Add a new rule of a grammar.
The rule is in a form of A -> B, where A, B \in ( N \cup T )+, and |A| <= |B|.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
void grammar::NonContractingGrammar< SymbolType >::addRules | ( | ext::vector< SymbolType > | leftHandSide, |
ext::set< ext::vector< SymbolType > > | rightHandSide | ||
) |
Add new rules of a grammar.
The rules are in form of A -> B | C | ..., where A, B, C ... \in ( N \cup T )+, and |A| <= |B|.
leftHandSide | the left hand side 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 |
bool grammar::NonContractingGrammar< SymbolType >::getGeneratesEpsilon |
Gets sign representing that grammar generates or doesn't generate empty word.
|
inline |
Getter of initial symbol.
|
inline |
Getter of initial symbol.
|
inline |
Getter of nonterminal alphabet.
|
inline |
Getter of nonterminal alphabet.
ext::map< ext::vector< SymbolType >, ext::set< ext::vector< SymbolType > > > && grammar::NonContractingGrammar< SymbolType >::getRules | ( | ) | && |
Get rules of the grammar.
const ext::map< ext::vector< SymbolType >, ext::set< ext::vector< SymbolType > > > & grammar::NonContractingGrammar< 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::NonContractingGrammar< SymbolType >::removeRule | ( | const ext::vector< SymbolType > & | leftHandSide, |
const ext::vector< SymbolType > & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> B, where A, B \in ( N \cup T )+, and |A| <= |B|.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
void grammar::NonContractingGrammar< SymbolType >::setGeneratesEpsilon | ( | bool | genEps | ) |
Sets sign representing that grammar generates or doesn't generate empty word.
genEps | sign representing the posibility of generating empty string from the grammar |
|
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 |