Add regular

This commit is contained in:
MaxanRus 2021-09-24 18:28:10 +03:00
parent 09ef97341f
commit a1843f4898
4 changed files with 59 additions and 2 deletions

View file

@ -15,7 +15,9 @@ include_directories(
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES)
set(SOURCE_FILES
src/regular/RegularTree.cpp
)
set(TEST_FILES)

View 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_;
};
}

View file

@ -1,5 +1,7 @@
#include <iostream>
#include "regular/RegularTree.hpp"
int main() {
std::cout << "hello world";
using namespace regular;
RegularTree reg_tree("(ab)*");
}

View 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);
}
}