7 #include <unordered_map> 39 typedef std::shared_ptr<expression const>
exptr;
64 literals(char32_t plus = U
'+', char32_t empty = U
'∅', char32_t epsilon = U
'ε',
65 char32_t star = U
'*', char32_t rPar = U
')', char32_t lPar = U
'(')
69 bool optimized =
false,
bool aggressive =
false);
71 bool optimized =
false,
bool aggressive =
false);
79 enum struct operation { empty, symbol, kleene, concatenation, alternation };
88 std::vector<exptr>::const_iterator
begin()
const;
89 std::vector<exptr>::const_iterator
end()
const;
102 static std::unordered_map<char32_t, exptr> symbols;
103 std::vector<exptr>
const subExpressions;
105 std::unique_ptr<dfa const>
mutable acceptingDfa;
char32_t const S
The Kleene star.
bool operator!=(expression const &r) const
Checks whether this RE is semantically different from another one.
Token literals as used in Introduction to Automata Theory, Languages, and Computation by Hopcroft...
char32_t const EMPTY
Neutral element of alternation and annihilating element of concatenation, a.k.a. empty set...
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 ε.
static exptr spawnFromString(std::u32string const &re, literals lits=literals(), bool optimized=false, bool aggressive=false)
Gives an RE encoded in a given string.
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.
std::string to_string() const
Describes this RE in UTF-8-encoded human-readable form.
bool operator==(expression const &r) const
Checks whether this RE is semantically equivalent to another one.
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.
char32_t const EPSILON
Neutral element of concatenation, a.k.a. empty string.
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 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.