Add regular
This commit is contained in:
parent
09ef97341f
commit
a1843f4898
|
@ -15,7 +15,9 @@ include_directories(
|
|||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(SOURCE_FILES)
|
||||
set(SOURCE_FILES
|
||||
src/regular/RegularTree.cpp
|
||||
)
|
||||
|
||||
set(TEST_FILES)
|
||||
|
||||
|
|
31
include/regular/RegularTree.hpp
Normal file
31
include/regular/RegularTree.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace regular {
|
||||
class RegularTree {
|
||||
public:
|
||||
class Node {
|
||||
public:
|
||||
Node();
|
||||
|
||||
void Parse(const std::string&);
|
||||
void Parse(const std::string_view);
|
||||
|
||||
enum class Type {
|
||||
Addition, Concatenation
|
||||
};
|
||||
std::variant<std::vector<std::unique_ptr<Node>>, std::string> value;
|
||||
Type type;
|
||||
private:
|
||||
};
|
||||
|
||||
RegularTree(const std::string&);
|
||||
|
||||
private:
|
||||
Node node_;
|
||||
};
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
#include <iostream>
|
||||
#include "regular/RegularTree.hpp"
|
||||
|
||||
int main() {
|
||||
std::cout << "hello world";
|
||||
using namespace regular;
|
||||
RegularTree reg_tree("(ab)*");
|
||||
}
|
||||
|
|
22
src/regular/RegularTree.cpp
Normal file
22
src/regular/RegularTree.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "regular/RegularTree.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace regular {
|
||||
RegularTree::Node::Node() {}
|
||||
|
||||
void RegularTree::Node::Parse(const std::string& regular) {
|
||||
Parse(std::string_view(regular.c_str(), regular.size()));
|
||||
}
|
||||
|
||||
void RegularTree::Node::Parse(const std::string_view regular) {
|
||||
const int n = regular.size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
std::cout << regular[i];
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
RegularTree::RegularTree(const std::string& regular) {
|
||||
node_.Parse(regular);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue