formalang/include/regular/RegularTree.hpp

45 lines
846 B
C++
Raw Normal View History

2021-09-24 15:28:10 +00:00
#pragma once
#include <vector>
#include <memory>
#include <string>
#include <string_view>
namespace regular {
class RegularTree {
public:
class Node {
public:
2021-09-26 23:59:08 +00:00
enum class Type {
Addition, Concatenation, Word
};
enum class Modifier {
Plus, Star, None
};
2021-09-24 15:28:10 +00:00
Node();
2021-09-26 23:59:08 +00:00
Node(Type);
2021-09-24 15:28:10 +00:00
void Parse(const std::string&);
2021-09-26 23:59:08 +00:00
void Print() const;
std::vector<std::unique_ptr<Node>> children;
std::string word;
2021-09-24 15:28:10 +00:00
Type type;
2021-09-26 23:59:08 +00:00
Modifier modifier = Modifier::None;
2021-10-05 15:13:31 +00:00
std::string ToString() const;
2021-09-24 15:28:10 +00:00
private:
2021-09-26 23:59:08 +00:00
void ParseCurrentType(const std::string_view);
2021-09-27 00:12:08 +00:00
void Compression();
2021-10-05 15:13:31 +00:00
void Compression2();
2021-09-26 23:59:08 +00:00
void Print(int nesting_level) const;
2021-09-24 15:28:10 +00:00
};
RegularTree(const std::string&);
2021-09-26 23:59:08 +00:00
const Node& GetNode() const;
void Print() const;
2021-10-05 15:13:31 +00:00
std::string ToString() const;
2021-09-24 15:28:10 +00:00
private:
Node node_;
};
}