Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
|
Left regular grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular languages. More...
#include <LeftRG.h>
Public Member Functions | |
LeftRG (NonterminalSymbolType initialSymbol) | |
Creates a new instance of Left regular grammar with a concrete initial symbol. More... | |
LeftRG (ext::set< NonterminalSymbolType > nonterminalAlphabet, ext::set< TerminalSymbolType > terminalAlphabet, NonterminalSymbolType initialSymbol) | |
Creates a new instance of Left regular grammar with a concrete nonterminal, terminal alphabet and initial symbol. More... | |
bool | addRule (NonterminalSymbolType leftHandSide, ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > rightHandSide) |
Add a new rule of a grammar. More... | |
void | addRules (NonterminalSymbolType leftHandSide, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > > rightHandSide) |
Add new rules of a grammar. More... | |
const ext::map< NonterminalSymbolType, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > > > & | getRules () const & |
ext::map< NonterminalSymbolType, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > > > && | getRules () && |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > &rightHandSide) |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const TerminalSymbolType &rightHandSide) |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const ext::pair< NonterminalSymbolType, TerminalSymbolType > &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 LeftRG &other) const |
bool | operator== (const LeftRG &other) const |
![]() | |
void | accessComponent () |
Friends | |
ext::ostream & | operator<< (ext::ostream &out, const LeftRG &instance) |
Additional Inherited Members | |
![]() | |
static void | registerComponent () |
static void | unregisterComponent () |
Left regular grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular languages.
Definition is similar to all common definitions of regular grammars. Additionaly contains boolean signaling whether the grammar generates empty string or don't. Hence the A -> \eps and not even S -> \eps, where A \in N is not allowed. G = (N, T, P, S, E), 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 -> Ba or A -> a, where A, B \in N and a \in T, S (InitialSymbol) = initial nonterminal symbol, E = boolean signaling wheter grammar generates empty string or don't.
This definition has simplier handling of empty string generation and it is compatible with common definitions where the transformation from this definition to the common definition and backwards is straightforward.
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 Left regular grammar with a concrete initial symbol.
initialSymbol | the initial symbol of the grammar |
|
explicit |
Creates a new instance of Left regular grammar with a concrete nonterminal, 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::LeftRG< TerminalSymbolType, NonterminalSymbolType >::addRule | ( | NonterminalSymbolType | leftHandSide, |
ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > | rightHandSide | ||
) |
Add a new rule of a grammar.
The rule is in a form of A -> Ba or A -> a, where A, B \in N and a \in T.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
void grammar::LeftRG< TerminalSymbolType, NonterminalSymbolType >::addRules | ( | NonterminalSymbolType | leftHandSide, |
ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > > | rightHandSide | ||
) |
Add new rules of a grammar.
The rules are in form of A -> Ba | Cb | ... | a | b | ..., where A, B, C ... \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::LeftRG< 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, TerminalSymbolType > > > > && grammar::LeftRG< TerminalSymbolType, NonterminalSymbolType >::getRules | ( | ) | && |
Get rules of the grammar.
const ext::map< NonterminalSymbolType, ext::set< ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > > > & grammar::LeftRG< 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::LeftRG< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const ext::pair< NonterminalSymbolType, TerminalSymbolType > & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> Ba, where A, B \in N and a \in T.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
bool grammar::LeftRG< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const ext::variant< TerminalSymbolType, ext::pair< NonterminalSymbolType, TerminalSymbolType > > & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> Ba or A -> a, where A, B \in N and a \in T.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
bool grammar::LeftRG< 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::LeftRG< 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 |