7 #include <unordered_map> 67 literals(char32_t plus = U
'+', char32_t empty = U
'∅', char32_t epsilon = U
'ε',
68 char32_t star = U
'*', char32_t rPar = U
')', char32_t lPar = U
'(')
72 bool optimized =
false,
bool aggressive =
false);
74 bool optimized =
false,
bool aggressive =
false);
84 enum struct operation { empty, symbol, kleene, concatenation, alternation };
87 operator nfa const&()
const;
char32_t const S
The Kleene star.
Represents nondeterministic finite automata with ε-moves.
static char32_t N
The symbol used to represent the Null/empty set in a regular expression.
char32_t const EMPTY
Neutral element of alternation and annihilating element of concatenation, a.k.a. empty set...
bool operator==(nfa const &other) const
Checks whether this RE describes the same regular language as another object.
std::vector< exptr >::const_iterator begin() const
Returns an iterator pointing to this RE's first subexpression.
static exptr const & spawnEmptyString()
Gives an RE representing the empty string ε.
bool operator!=(nfa const &other) const
Checks whether this RE describes a different regular language than another object.
static exptr spawnAlternation(exptr const &l, exptr const &r, bool optimized=true, bool aggressive=false)
Gives an RE representing the alternation of two given REs.
Represents formal regular expressions.
std::u32string to_u32string() const
Describes this RE in UTF-32-encoded human-readable form.
char32_t extractSymbol() const
Reports this symbol expression's UTF-32-encoded symbol.
static exptr const & spawnSymbol(char32_t symbol)
Gives an RE representing the given UTF-32-encoded symbol.
operation
The different purposes an RE may fulfill.
operation getOperation() const
Reports this RE's function.
std::vector< exptr >::const_iterator end() const
Returns an iterator pointing behind this RE's last subexpression.
static char32_t K
The symbol used to represent the Kleene star in a regular expression.
std::string to_string() const
Describes this RE in UTF-8-encoded human-readable form.
char32_t const L
The left parenthesis.
char32_t const P
The alternation symbol.
size_t size() const
Reports the size of this RE's tree representation.
static exptr spawnFromString(std::u32string const &re, literals lits, bool optimized=false, bool aggressive=false)
static char32_t L
The symbol used to represent the Left parenthesis in a regular expression.
Where this library lives.
char32_t const EPSILON
Neutral element of concatenation, a.k.a. empty string.
static void reset()
Resets the symbols used for RE operators to their defaults.
static char32_t E
The symbol used to represent the Empty string in a regular expression.
std::shared_ptr< expression const > exptr
This is the type used to handle regular expressions.
static exptr const & spawnEmptySet()
Gives an RE representing the empty set ∅.
char32_t const R
The right parenthesis.
std::string extractUtf8Symbol() const
Reports this symbol expression's UTF-8-encoded symbol.
literals(char32_t plus=U'+', char32_t empty=U '∅', char32_t epsilon=U 'ε', char32_t star=U' *', char32_t rPar=U')', char32_t lPar=U'(')
static char32_t R
The symbol used to represent the Right parenthesis in a regular expression.
static exptr spawnKleene(exptr const &b, bool optimized=true, bool aggressive=false)
Gives an RE representing the Kleene closure of a given RE.
static exptr spawnConcatenation(exptr const &l, exptr const &r, bool optimized=true, bool aggressive=false)
Gives an RE representing the concatenation of two given REs.
static char32_t A
The symbol used to represent the Alternation in a regular expression.