Skip to content
Snippets Groups Projects
Commit 3ebc5e40 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

sample comments

parent 20c8fa05
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ namespace grammar {
* G = (N, T, P, S, E)
* N = nonempty finite set of nonterminal symbols
* T = finite set of terminal symbols - having this empty won't let grammar do much though
* P = set of production rules of the form A -> aB or A -> a (where A, B \in N and a \in T)
* P = set of production rules of the form A -> aB or A -> a, where A, B \in N and a \in T
* S = initial nonterminal symbol
* E = boolean signaling wheter grammar generates empty string or don't
*
......@@ -38,43 +38,122 @@ class LeftRG : public std::element<LeftRG, GrammarBase>, public TerminalNontermi
*/
bool generatesEpsilon;
public:
/**
* Creates a new instance of Left regular grammar with concrete initial symbol
*/
LeftRG(const alphabet::Symbol& initialSymbol);
 
/**
* Creates a new instance of Left regular grammar with concrete nonterminal, terminal alphabet and initial symbol
*/
LeftRG(const std::set<alphabet::Symbol>& nonTerminalSymbols, const std::set<alphabet::Symbol>& terminalSymbols, const alphabet::Symbol& initialSymbol);
 
/**
* @copydoc alib::base::clone()
*/
virtual GrammarBase* clone() const;
 
/**
* @copydoc alib::base::plunder()
*/
virtual GrammarBase* plunder() &&;
 
/**
* Add a new rule of a grammar in form of A -> aB or A -> a, where A, B \in N and a \in T
*/
bool addRule(const alphabet::Symbol& leftHandSide, const std::variant<alphabet::Symbol, std::pair<alphabet::Symbol, alphabet::Symbol>>& rightHandSide);
/**
* Add a new rule of a grammar in form of A -> a, where A \in N and a \in T
*/
bool addRule(const alphabet::Symbol& leftHandSide, const alphabet::Symbol& rightHandSide);
/**
* Add a new rule of a grammar in form of A -> aB, where A, B \in N and a \in T
*/
bool addRule(const alphabet::Symbol& leftHandSide, const std::pair<alphabet::Symbol, alphabet::Symbol>& rightHandSide);
 
/**
* Get rules of the grammar
*/
const std::map<alphabet::Symbol, std::set<std::variant<alphabet::Symbol, std::pair<alphabet::Symbol, alphabet::Symbol>>>> getRules() const;
 
/**
* Add a new rule of a grammar in form of A -> aB or A -> a, where A, B \in N and a \in T
*/
bool removeRule(const alphabet::Symbol& leftHandSide, const std::variant<alphabet::Symbol, std::pair<alphabet::Symbol, alphabet::Symbol>>& rightHandSide);
/**
* Add a new rule of a grammar in form of A -> a, where A \in N and a \in T
*/
bool removeRule(const alphabet::Symbol& leftHandSide, const alphabet::Symbol& rightHandSide);
/**
* Add a new rule of a grammar in form of A -> aB, where A, B \in N and a \in T
*/
bool removeRule(const alphabet::Symbol& leftHandSide, const std::pair<alphabet::Symbol, alphabet::Symbol>& rightHandSide);
 
bool removeTerminalSymbol(const alphabet::Symbol& symbol);
/**
* @copydoc TerminalNonterminalAlphabetInitialSymbol::removeTerminalSymbol()
*/
virtual bool removeTerminalSymbol(const alphabet::Symbol& symbol);
 
bool removeNonterminalSymbol(const alphabet::Symbol& symbol);
/**
* @copydoc TerminalNonterminalAlphabetInitialSymbol::removeNonterminalSymbol()
*/
virtual bool removeNonterminalSymbol(const alphabet::Symbol& symbol);
 
/**
* Sets sing representing that grammar generates or doesn't generate empty word
*/
void setGeneratesEpsilon(bool genEps);
/**
* Gets sing representing that grammar generates or doesn't generate empty word
*/
bool getGeneratesEpsilon() const;
 
/**
* double dispatch operator helper
*/
virtual bool operator <(const GrammarBase& other) const;
/**
* double dispatch operator helper
*/
virtual bool operator ==(const GrammarBase& other) const;
/**
* double dispatch operator helper
*/
virtual bool operator >(const GrammarBase& other) const;
 
/**
* equals operator
* @param other the other instance
*/
virtual bool operator==(const LeftRG& other) const;
 
/**
* less operator
* @param other the other instance
*/
virtual bool operator<(const LeftRG& other) const;
 
/**
* print this instance as raw representation to ostream
* @param os ostream where to print
*/
virtual void operator>>(std::ostream& os) const;
 
/**
* casts this instance to as compact as possible string representation
*/
virtual operator std::string () const;
 
/**
* @copydoc alib::base_base::selfTypeId
*/
virtual int selfTypeId() const {
return typeId(*this);
}
......
......@@ -16,17 +16,31 @@
namespace grammar {
 
/**
* Abstract class representing grammar. Implements methods for manipulation
* with terminal and nonterminal symbols. Only method, which is not implemented
* is grammar specific isValidRule.
* Abstract class representing nonterminal and terminal alphabets and initial symbol. Implements methods for manipulation
* with terminal and nonterminal alphabets. Only pure virtual methods are remove terminal and nonterminal symbol.
*/
class TerminalNonterminalAlphabetInitialSymbol {
protected:
/**
* terminal alphabet
*/
std::set<alphabet::Symbol> terminalAlphabet;
/**
* nonterminal alphabet
*/
std::set<alphabet::Symbol> nonterminalAlphabet;
/**
* initial symbol
*/
alphabet::Symbol initialSymbol;
 
public:
/**
* Creates a new instance, initial symbol is included in the nonterminal alphabet
* @param initialSymbol
*/
TerminalNonterminalAlphabetInitialSymbol(const alphabet::Symbol& initialSymbol);
 
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment