Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
|
Context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy. Generates context free languages. More...
#include <LG.h>
Public Member Functions | |
LG (NonterminalSymbolType initialSymbol) | |
Creates a new instance of the grammar with a concrete initial symbol. More... | |
LG (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< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > rightHandSide) |
Add a new rule of a grammar. More... | |
void | addRules (NonterminalSymbolType leftHandSide, ext::set< ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > > rightHandSide) |
Add new rules of a grammar. More... | |
const ext::map< NonterminalSymbolType, ext::set< ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > > > & | getRules () const & |
ext::map< NonterminalSymbolType, ext::set< ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > > > && | getRules () && |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > &rightHandSide) |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const ext::vector< TerminalSymbolType > &rightHandSide) |
bool | removeRule (const NonterminalSymbolType &leftHandSide, const ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< 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) |
auto | operator<=> (const LG &other) const |
bool | operator== (const LG &other) const |
![]() | |
void | accessComponent () |
Friends | |
ext::ostream & | operator<< (ext::ostream &out, const LG &instance) |
Additional Inherited Members | |
![]() | |
static void | registerComponent () |
static void | unregisterComponent () |
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 -> B, where A \in N and B \in ( N \cup 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::LG< TerminalSymbolType, NonterminalSymbolType >::addRule | ( | NonterminalSymbolType | leftHandSide, |
ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > | rightHandSide | ||
) |
Add a new rule of a grammar.
The rule is in a form of A -> aBb or A -> a, where A, B, \in N and a, b \in T*.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
void grammar::LG< TerminalSymbolType, NonterminalSymbolType >::addRules | ( | NonterminalSymbolType | leftHandSide, |
ext::set< ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > > | rightHandSide | ||
) |
Add new rules of a grammar.
The rules are in form of A -> aBb | cCd | ... | e | f | ..., where A, B, C \in N and a, b, c, d, e, f ... \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 |
|
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< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > > > && grammar::LG< TerminalSymbolType, NonterminalSymbolType >::getRules | ( | ) | && |
Get rules of the grammar.
const ext::map< NonterminalSymbolType, ext::set< ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > > > & grammar::LG< 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::LG< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> aBb, where A, B \in N and a, b \in T*.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
bool grammar::LG< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const ext::variant< ext::vector< TerminalSymbolType >, ext::tuple< ext::vector< TerminalSymbolType >, NonterminalSymbolType, ext::vector< TerminalSymbolType > > > & | rightHandSide | ||
) |
Remove a rule of a grammar in form of A -> aBb or A -> a, where A, B \in N and a, b \in T*.
leftHandSide | the left hand side of the rule |
rightHandSide | the right hand side of the rule |
bool grammar::LG< TerminalSymbolType, NonterminalSymbolType >::removeRule | ( | const NonterminalSymbolType & | leftHandSide, |
const ext::vector< 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 |
|
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 |