|
Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
|
Context sensitive grammar in Chomsky hierarchy or type 1 in Chomsky hierarchy. Generates context sensitive languages. More...
#include <CSG.h>
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::ostream & | operator<< (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 () |
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,
| 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::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 )*.
| 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::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 )*.
| 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 |
| bool grammar::CSG< 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::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > && grammar::CSG< 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::CSG< 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::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 )*.
| 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::CSG< 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 |