|
Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
|
Unrestricted grammar. Type 0 in Chomsky hierarchy. Generates recursively enumerable languages. More...
#include <UnrestrictedGrammar.h>
Public Member Functions | |
| UnrestrictedGrammar (SymbolType initialSymbol) | |
| Creates a new instance of the grammar with a concrete initial symbol. More... | |
| UnrestrictedGrammar (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) |
| auto | operator<=> (const UnrestrictedGrammar &other) const |
| bool | operator== (const UnrestrictedGrammar &other) const |
Public Member Functions inherited from core::Components< UnrestrictedGrammar< DefaultSymbolType >, ext::set< DefaultSymbolType >, component::Set, std::tuple< TerminalAlphabet, NonterminalAlphabet >, DefaultSymbolType, component::Value, InitialSymbol > | |
| void | accessComponent () |
Friends | |
| ext::ostream & | operator<< (ext::ostream &out, const UnrestrictedGrammar &instance) |
Additional Inherited Members | |
Static Public Member Functions inherited from core::Components< UnrestrictedGrammar< DefaultSymbolType >, ext::set< DefaultSymbolType >, component::Set, std::tuple< TerminalAlphabet, NonterminalAlphabet >, DefaultSymbolType, component::Value, InitialSymbol > | |
| static void | registerComponent () |
| static void | unregisterComponent () |
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 -> B, where A \in N, B, \alpha, and \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::UnrestrictedGrammar< SymbolType >::addRule | ( | ext::vector< SymbolType > | leftHandSide, |
| ext::vector< SymbolType > | rightHandSide | ||
| ) |
Add a new rule of a grammar.
The rule is in a form of \alpha A \beta -> B, where A \in N, B, \alpha, and \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::UnrestrictedGrammar< SymbolType >::addRules | ( | ext::vector< SymbolType > | leftHandSide, |
| ext::set< ext::vector< SymbolType > > | rightHandSide | ||
| ) |
Add new rules of a grammar.
The rules are in form of \alpha A \beta -> B | C | ..., where A \in N, B, C ..., \alpha, and \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::vector< SymbolType >, ext::set< ext::vector< SymbolType > > > && grammar::UnrestrictedGrammar< SymbolType >::getRules | ( | ) | && |
Get rules of the grammar.
| const ext::map< ext::vector< SymbolType >, ext::set< ext::vector< SymbolType > > > & grammar::UnrestrictedGrammar< 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::UnrestrictedGrammar< SymbolType >::removeRule | ( | const ext::vector< SymbolType > & | leftHandSide, |
| const ext::vector< SymbolType > & | rightHandSide | ||
| ) |
Remove a rule of a grammar in form of \alpha A \beta -> B, where A \in N, B, \alpha, and \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 |