Browse Source

添加项目文件。

ToiletMaster 6 months ago
parent
commit
c71f7380d8
12 changed files with 657 additions and 0 deletions
  1. 31 0
      FSM-OO.sln
  2. 144 0
      FSM-OO/FSM-OO.vcxproj
  3. 48 0
      FSM-OO/FSM-OO.vcxproj.filters
  4. 49 0
      FSM-OO/automata.cpp
  5. 43 0
      FSM-OO/automata.h
  6. 143 0
      FSM-OO/example-test1.cpp
  7. 6 0
      FSM-OO/example.h
  8. 6 0
      FSM-OO/main.cpp
  9. 20 0
      FSM-OO/state.cpp
  10. 35 0
      FSM-OO/state.h
  11. 15 0
      FSM-OO/tape.h
  12. 117 0
      FSM-OO/test1.cpp

+ 31 - 0
FSM-OO.sln

@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.35122.118
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FSM-OO", "FSM-OO\FSM-OO.vcxproj", "{38F545A9-2A41-4F27-BD27-6408E0C17AC9}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Debug|x64.ActiveCfg = Debug|x64
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Debug|x64.Build.0 = Debug|x64
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Debug|x86.ActiveCfg = Debug|Win32
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Debug|x86.Build.0 = Debug|Win32
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Release|x64.ActiveCfg = Release|x64
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Release|x64.Build.0 = Release|x64
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Release|x86.ActiveCfg = Release|Win32
+		{38F545A9-2A41-4F27-BD27-6408E0C17AC9}.Release|x86.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {65B611DE-C4FA-41BC-B581-3760BB029FD1}
+	EndGlobalSection
+EndGlobal

+ 144 - 0
FSM-OO/FSM-OO.vcxproj

@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <VCProjectVersion>17.0</VCProjectVersion>
+    <Keyword>Win32Proj</Keyword>
+    <ProjectGuid>{38f545a9-2a41-4f27-bd27-6408e0c17ac9}</ProjectGuid>
+    <RootNamespace>FSMOO</RootNamespace>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="Shared">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="automata.cpp" />
+    <ClCompile Include="example-test1.cpp" />
+    <ClCompile Include="main.cpp" />
+    <ClCompile Include="state.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="automata.h" />
+    <ClInclude Include="example.h" />
+    <ClInclude Include="state.h" />
+    <ClInclude Include="tape.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 48 - 0
FSM-OO/FSM-OO.vcxproj.filters

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="源文件">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="头文件">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
+    </Filter>
+    <Filter Include="资源文件">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+    <Filter Include="example">
+      <UniqueIdentifier>{a8a27989-538d-418e-9ca3-b6a04f5147e0}</UniqueIdentifier>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="state.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="automata.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="main.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="example-test1.cpp">
+      <Filter>example</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="state.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="automata.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="example.h">
+      <Filter>example</Filter>
+    </ClInclude>
+    <ClInclude Include="tape.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+  </ItemGroup>
+</Project>

+ 49 - 0
FSM-OO/automata.cpp

@@ -0,0 +1,49 @@
+#include "automata.h"
+
+namespace L87 {
+	Automata::Error::Error() {
+		name = "unknown"; // TBD  反制魔法字符串
+		details = "undefined error"; // TBD  反制魔法字符串
+	}
+
+	Automata::Error::Error(std::string& _name) {
+		InnerMapIterator it = Inner_Error_Table.find(_name);
+		if (it != Inner_Error_Table.end()) {
+			name = it->first.c_str();
+			details = it->second.c_str();
+		}
+		else {
+			name = "unknown";
+			details = "undefined error";
+		}
+	}
+
+	Automata::Error::InnerMap Automata::Error::Inner_Error_Table;
+}
+
+namespace L87 {
+	Automata::Result::Result(State* _state) : state(_state) {}
+}
+
+namespace L87 {
+	Automata::Automata(StateDiagram& _diagram) : diagram(_diagram) {}
+	Automata::Result Automata::Run(std::string _input) {
+		State* current = diagram.initial;
+		Result result(current);
+		result.value = current->name();
+		for (auto& item : _input) {
+			result.state = current = current->next(item);
+			result.value += " -> ";
+			result.value += current->name();
+			if (current->bad()) {
+				// TBD
+				break;
+			}
+			if (current->done()) {
+				// TBD
+				break;
+			}
+		}
+		return result; // 拷贝构造
+	}
+}

+ 43 - 0
FSM-OO/automata.h

@@ -0,0 +1,43 @@
+#pragma once
+
+#include <string>
+#include <unordered_map>
+#include "state.h"
+#include "tape.h"
+
+namespace L87 {
+	class Automata {
+	public:
+		// TBD Ìí¼Ó´íÎóÐÅϢʹÓÃ
+		struct Error {
+			using InnerMap = std::unordered_map<std::string, std::string>;
+			using InnerMapIterator = InnerMap::iterator;
+
+		private:
+			static InnerMap Inner_Error_Table;
+
+		public:
+			const char* name;
+			const char* details;
+			Error();
+			Error(std::string& _name);
+		};
+
+	public:
+		struct Error;
+		struct Result {
+		public:
+			State* state;
+			Error error;
+			std::string value;
+			Result(State* _state);
+		};
+
+	protected:
+		StateDiagram& diagram;
+
+	public:
+		Automata(StateDiagram& _diagram);
+		Result Run(std::string _input);
+	};
+}

+ 143 - 0
FSM-OO/example-test1.cpp

@@ -0,0 +1,143 @@
+#include <iostream>
+#include <string>
+#include <mutex>
+
+#include "example.h"
+
+using namespace L87;
+
+class S1 : public State {
+public:
+	S1(StateDiagram* parent) : State(parent) { auto_register(); }
+	const char* name() override { return "S1"; }
+	virtual State* next(char input) override {
+		if (input == 'a') {
+			return states["S2"];
+		}
+		if (input == 'b') {
+			return this; // states["S1"];
+		}
+		return states["E"];
+	}
+};
+
+class S2 : public State {
+public:
+	S2(StateDiagram* parent) : State(parent) { auto_register(); }
+	virtual const char* name() override { return "S2"; }
+	virtual State* next(char input) override {
+		if (input == 'a') {
+			return states["S3"];
+		}
+		if (input == 'b') {
+			return this; // states["S2"];
+		}
+		if (input == 'c') {
+			return states["T"];
+		}
+		return states["E"];
+	}
+};
+
+class S3 : public State {
+public:
+	S3(StateDiagram* parent) : State(parent) { auto_register(); }
+	virtual const char* name() override { return "S3"; }
+	virtual State* next(char input) override {
+		if (input == 'a') {
+			return states["S1"];
+		}
+		if (input == 'b') {
+			return this; // states["S3"];
+		}
+		return states["E"];
+	}
+};
+
+class T : public State {
+public:
+	T(StateDiagram* parent) : State(parent) { auto_register(); }
+	virtual const char* name() override { return "T"; }
+	virtual State* next(char input) override {
+		return this; // states["T"];
+	}
+	virtual bool done() override { return true; }
+};
+
+class E : public State {
+public:
+	E(StateDiagram* parent) : State(parent) { auto_register(); }
+	virtual const char* name() override { return "E"; }
+	virtual State* next(char input) override {
+		return this; // states["E"];
+	}
+	virtual bool done() override { return true; }
+	virtual bool bad() override { return true; }
+};
+
+class TestStateDiagram : public StateDiagram {
+private:
+	static TestStateDiagram* instance;
+	static std::mutex mtx;
+private:
+	TestStateDiagram() {
+		initial = new S1(this);
+		new S2(this);
+		new S3(this);
+		new T(this);
+		new E(this);
+	}
+public:
+	static TestStateDiagram& Instance() {
+		if (instance == nullptr) {
+			mtx.lock();
+			if (instance == nullptr) {
+				instance = new TestStateDiagram();
+			}
+			mtx.unlock();
+		}
+		return *instance;
+	}
+	static void Destory() {
+		if (instance != nullptr) {
+			mtx.lock();
+			if (instance != nullptr) {
+				TestStateDiagram* to_del = instance;
+				instance = nullptr;
+				delete to_del;
+			}
+			mtx.unlock();
+		}
+	}
+};
+
+TestStateDiagram* TestStateDiagram::instance = nullptr;
+std::mutex TestStateDiagram::mtx;
+
+void test1() {
+	// TestStateDiagram ״̬ͼ°üº¬ 5 ¸ö״̬: S1, S2, S3, T, E
+	// s	a	b	c	oth
+	// S1	S2	S1	E	E
+	// S2	S3	S2	T	E
+	// S3	S1	S3	E	E
+	// T	T	T	T	T
+	// E	E	E	E	E
+
+	L87::Automata automata(TestStateDiagram::Instance());
+	{
+		std::string input = "ab?!ababac";
+		L87::Automata::Result result = automata.Run(input);
+		std::cout << input << ": " << result.value << std::endl;
+	}
+	{
+		std::string input = "abababaabccasvsddb";
+		L87::Automata::Result result = automata.Run(input);
+		std::cout << input << ": " << result.value << std::endl;
+	}
+	{
+		std::string input = "abaabbbaaaac";
+		L87::Automata::Result result = automata.Run(input);
+		std::cout << input << ": " << result.value << std::endl;
+	}
+	TestStateDiagram::Destory();
+}

+ 6 - 0
FSM-OO/example.h

@@ -0,0 +1,6 @@
+#pragma once
+
+#include "automata.h"
+#include "state.h"
+
+void test1();

+ 6 - 0
FSM-OO/main.cpp

@@ -0,0 +1,6 @@
+#include "example.h"
+
+int main() {
+	test1();
+	return 0;
+}

+ 20 - 0
FSM-OO/state.cpp

@@ -0,0 +1,20 @@
+#include "state.h"
+
+namespace L87 {
+	StateDiagram::~StateDiagram() {
+		for (auto it : states) {
+			delete it.second;
+		}
+	}
+}
+
+namespace L87 {
+	void State::auto_register() { states.insert({ name(), this }); }
+
+	State::State(StateDiagram* _diagram) : diagram(_diagram), states(_diagram->states) { }
+
+	bool State::done() { return false; }
+
+	bool State::bad() { return false; }
+
+}

+ 35 - 0
FSM-OO/state.h

@@ -0,0 +1,35 @@
+#pragma once
+
+#include <string>
+#include <unordered_map>
+
+namespace L87 {
+	class State;
+
+	struct StateDiagram {
+		::std::unordered_map<::std::string, State*> states;
+		State* initial;
+		virtual ~StateDiagram();
+	};
+}
+
+namespace L87 {
+	struct StateDiagram;
+
+	class State {
+	protected:
+		StateDiagram* diagram;
+		::std::unordered_map<::std::string, State*>& states;
+		void auto_register();
+
+	public:
+		State(StateDiagram* _diagram);
+		virtual bool done();
+		virtual bool bad();
+
+	public:
+		// ¾ßÌå״̬±ØÐëʵÏÖ
+		virtual const char* name() = 0;
+		virtual State* next(char input) = 0;
+	};
+}

+ 15 - 0
FSM-OO/tape.h

@@ -0,0 +1,15 @@
+#pragma once
+
+namespace Automata {
+	template<class Container>
+	struct Tape {
+		using Iterator = typename Container::iterator;
+
+	public:
+		Container container;
+		Tape(Container& _container) : container(_container) {}
+		size_t size() { return container.size(); }
+		Iterator begin() { return container.begin(); }
+		Iterator end() { return container.end(); }
+	};
+}

+ 117 - 0
FSM-OO/test1.cpp

@@ -0,0 +1,117 @@
+#include <iostream>
+#include <string>
+#include <mutex>
+
+#include "automata.h"
+#include "state.h"
+
+using namespace L87;
+
+class S1 : public State {
+public:
+	S1(StateDiagram* parent) : State(parent) { _register(); }
+	const char* name() override { return "S1"; }
+	virtual State* next(char input) override {
+		if (input == 'a') {
+			return states["S2"];
+		}
+		if (input == 'b') {
+			return this; // states["S1"];
+		}
+		return states["E"];
+	}
+};
+
+class S2 : public State {
+public:
+	S2(StateDiagram* parent) : State(parent) { _register(); }
+	virtual const char* name() override { return "S2"; }
+	virtual State* next(char input) override {
+		if (input == 'a') {
+			return states["S3"];
+		}
+		if (input == 'b') {
+			return states["T"];
+		}
+		return states["E"];
+	}
+};
+
+class S3 : public State {
+public:
+	S3(StateDiagram* parent) : State(parent) { _register(); }
+	virtual const char* name() override { return "S3"; }
+	virtual State* next(char input) override {
+		if (input == 'a') {
+			return states["S1"];
+		}
+		return states["E"];
+	}
+};
+
+class T : public State {
+public:
+	T(StateDiagram* parent) : State(parent) { _register(); }
+	virtual const char* name() override { return "T"; }
+	virtual State* next(char input) override {
+		return this; // states["T"];
+	}
+	virtual bool done() override { return true; }
+};
+
+class E : public State {
+public:
+	E(StateDiagram* parent) : State(parent) { _register(); }
+	virtual const char* name() override { return "E"; }
+	virtual State* next(char input) override {
+		return this; // states["E"];
+	}
+	virtual bool done() override { return true; }
+	virtual bool bad() override { return true; }
+};
+
+class TestStateDiagram : public StateDiagram {
+private:
+	static TestStateDiagram* instance;
+private:
+	TestStateDiagram() {
+		initial = new S1(this);
+		new S2(this);
+		new S3(this);
+		new T(this);
+		new E(this);
+	}
+
+	~TestStateDiagram() {
+		for (auto it : states) {
+			delete it.second;
+		}
+	}
+public:
+	static TestStateDiagram& Instance() {
+		if (instance == nullptr) {
+			if (instance == nullptr) {
+				instance = new TestStateDiagram();
+			}
+		}
+		return *instance;
+	}
+};
+TestStateDiagram* TestStateDiagram::instance = nullptr;
+
+int test1() {
+	Automata automata(TestStateDiagram::Instance());
+	{
+		std::string input = "aaaab";
+		Automata::Result result = automata.Run(input);
+		std::string str((char*)result.value);
+		std::cout << input << ':' << str << std::endl;
+	}
+	{
+		std::string input = "aaaaaaaaaaaaaaaab";
+		Automata::Result result = automata.Run(input);
+		std::string str((char*)result.value);
+		std::cout << input << ':' << str << std::endl;
+	}
+	return 0;
+}