Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
|
Chomsky normal form of a context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy. Generates context free languages. More...
#include <CNF.h>
Public Member Functions | |
CNF (NonterminalSymbolType initialSymbol) | |
Creates a new instance of the grammar with a concrete initial symbol. More... | |
CNF (ext::set< NonterminalSymbolType > nonterminalAlphabet, ext::set< TerminalSymbolType > terminalAlphabet, NonterminalSymbolType initialSymbol) | |
Creates a new instance of the grammar with a concrete nonterminal alphabet, terminal alphabet and initial symbol. More... | |
bool | addRule (NonterminalSymbolType leftHandSide, ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > rightHandSide) |
Add a new rule of a grammar. More... | |
void | addRules (NonterminalSymbolType leftHandSide, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > > rightHandSide) |
Add new rules of a grammar. More... | |
const ext::map< NonterminalSymbolType, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > > > & | getRules () const & |
ext::map< NonterminalSymbolType, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > > > && | getRules () && |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > &rightHandSide) |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const TerminalSymbolType &rightHandSide) |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const ext::pair< NonterminalSymbolType, NonterminalSymbolType > &rightHandSide) |
const NonterminalSymbolType & | getInitialSymbol () const & |
NonterminalSymbolType && | getInitialSymbol () && |
bool | setInitialSymbol (NonterminalSymbolType symbol) |
const ext::set< NonterminalSymbolType > & | getNonterminalAlphabet () const & |
ext::set< NonterminalSymbolType > && | getNonterminalAlphabet () && |
bool | addNonterminalSymbol (NonterminalSymbolType symbol) |
void | setNonterminalAlphabet (ext::set< NonterminalSymbolType > symbols) |
const ext::set< TerminalSymbolType > & | getTerminalAlphabet () const & |
ext::set< TerminalSymbolType > && | getTerminalAlphabet () && |
bool | addTerminalSymbol (TerminalSymbolType symbol) |
void | setTerminalAlphabet (ext::set< TerminalSymbolType > symbols) |
void | setGeneratesEpsilon (bool genEps) |
bool | getGeneratesEpsilon () const |
auto | operator<=> (const CNF &other) const |
bool | operator== (const CNF &other) const |
![]() | |
void | accessComponent () |
Friends | |
ext::ostream & | operator<< (ext::ostream &out, const CNF &instance) |
Additional Inherited Members | |
![]() | |
static void | registerComponent () |
static void | unregisterComponent () |
Chomsky normal form of a context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy. Generates context free languages.
Definition is similar to all common definitions of context free 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 -> BC or A -> a, where A, B, C \in N and a \in T, S (InitialSymbol) = initial nonterminal symbol,
TerminalSymbolType | used for the terminal alphabet of the grammar. |
NonterminalSymbolType | used for 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::CNF< TerminalSymbolType, NonterminalSymbolType >::addRule | ( | NonterminalSymbolType | leftHandSide, |
ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > | rightHandSide | ||
) |
Add a new rule of a grammar.
The rule is in a form of A -> BC or A -> a, where A, B, C, \in N and a \in T.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
void grammar::CNF< TerminalSymbolType, NonterminalSymbolType >::addRules | ( | NonterminalSymbolType | leftHandSide, |
ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > > | rightHandSide | ||
) |
Add new rules of a grammar.
The rules are in form of A -> BC | DE | ... | a | b | ..., where A, B, C, D, E \in N and a, b in T.
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::CNF< TerminalSymbolType, NonterminalSymbolType >::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< NonterminalSymbolType, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > > > && grammar::CNF< TerminalSymbolType, NonterminalSymbolType >::getRules | ( | ) | && |
Get rules of the grammar.
const ext::map< NonterminalSymbolType, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > > > & grammar::CNF< TerminalSymbolType, NonterminalSymbolType >::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::CNF< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const ext::pair< NonterminalSymbolType, NonterminalSymbolType > & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> BC, where A, B, C.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
bool grammar::CNF< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, NonterminalSymbolType > > & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> BC or A -> a, where A, B, C \in N and a \in T.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
bool grammar::CNF< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const TerminalSymbolType & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> a, where A \in N and a \in T.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
void grammar::CNF< TerminalSymbolType, NonterminalSymbolType >::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 |