自作言語nullptrのインタープリターです。
Revision | 2f9a4d9b0c2432c2e2929890c583fe939b5ced02 (tree) |
---|---|
Time | 2015-08-10 23:29:32 |
Author | Diverge <diverge.vosystems@gmai...> |
Commiter | Diverge |
Begin to split Interpreter source file
Nullptr
|--Preprocessor
|--Module
|--Interpreter
@@ -4,7 +4,7 @@ | ||
4 | 4 | */ |
5 | 5 | |
6 | 6 | #include"nullptr.h" |
7 | -#include"nullptrInterpreter.h" | |
7 | +#include"Interpreter.h" | |
8 | 8 | #include<iostream> |
9 | 9 | #include<fstream> |
10 | 10 | #include<direct.h> |
@@ -4,7 +4,7 @@ | ||
4 | 4 | */ |
5 | 5 | |
6 | 6 | #include"nullptr.h" |
7 | -#include"nullptrInterpreter.h" | |
7 | +#include"Interpreter.h" | |
8 | 8 | #include<iostream> |
9 | 9 | #include<fstream> |
10 | 10 | #include<direct.h> |
@@ -1,2 +1,2 @@ | ||
1 | 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit |
2 | -Debug|Win32|C:\Users\VOSystems\Documents\Visual Studio 2015\Projects\nullptr\| | |
2 | +Debug|Win32|C:\Users\VOSystems\documents\visual studio 2015\Projects\nullptr\| |
@@ -0,0 +1,84 @@ | ||
1 | +/* | |
2 | +nullptr Interpreter. | |
3 | +(C) 2015 VOSystems. | |
4 | +*/ | |
5 | + | |
6 | +#pragma once | |
7 | + | |
8 | +#include<vector> | |
9 | +#include<string> | |
10 | +#include<regex> | |
11 | +#include<fstream> | |
12 | +#include"nullptr.h" | |
13 | + | |
14 | +namespace VOSystemsNullptr | |
15 | +{ | |
16 | + namespace Core | |
17 | + { | |
18 | + class Interpreter | |
19 | + { | |
20 | + private: | |
21 | + std::vector<BasicTypes::IntManager> m_int;//Int変数リスト | |
22 | + std::vector<BasicTypes::String> m_string;//String変数リスト | |
23 | + std::vector<BasicTypes::Bool> m_bool;//bool変数リスト | |
24 | + System::IdentifierList m_list;//識別子リスト | |
25 | + | |
26 | + std::string m_workline;//行の内容(セミコロンの次からセミコロンまで) | |
27 | + | |
28 | + std::streamoff m_eip;//x86のEIPと同じ、命令ポインタ | |
29 | + std::string m_src;//ソースファイル名 | |
30 | + | |
31 | + void LineLoad(void);//行読み込み | |
32 | + void Extract(void);//プリプロセッサー、展開 | |
33 | + void Trim(void);//プリプロセッサー、除去 | |
34 | + | |
35 | + | |
36 | + std::string m_stdout,m_stdin,m_stderr;//標準入出力系の名前 | |
37 | + | |
38 | + std::vector<std::string> Split(const std::string &str, const std::string &delim);//文字列分割 | |
39 | + std::string Replace(std::string src, std::string before, std::string after);//文字列置き換え | |
40 | + bool Find(const std::string& str, const std::string& find);//文字列検索 | |
41 | + | |
42 | + void Screen(std::string line);//ベーシックモジュール->標準出力 | |
43 | + void Keyboard(std::string line);//ベーシックモジュール->標準入力 | |
44 | + void EScreen(std::string line);//ベーシックモジュール標準エラー出力 | |
45 | + | |
46 | + bool NewInt(std::string name, BasicTypes::Int value);//Int変数作成 | |
47 | + bool AssignInt(std::string name, BasicTypes::Int value);//Int変数代入 | |
48 | + bool GetInt(std::string name, BasicTypes::Int& target);//Int変数、値取得 | |
49 | + | |
50 | + bool NewStr(std::string name, std::string value);//String変数作成 | |
51 | + bool AssignStr(std::string name, std::string value);//String変数代入 | |
52 | + bool GetStr(std::string name, std::string& target);//String変数、値取得 | |
53 | + | |
54 | + bool NewVar(std::string line);//変数作成 | |
55 | + | |
56 | + bool If(std::string line); | |
57 | + bool For(std::string line); | |
58 | + bool While(std::string line); | |
59 | + bool Loop(std::string line); | |
60 | + bool Switch(std::string line); | |
61 | + bool Goto(std::string line); | |
62 | + bool GetBool(std::string judge); | |
63 | + | |
64 | + std::vector<std::string> Lex(std::string formula); | |
65 | + std::vector<std::string> ReplaceVar2Num(std::vector<std::string> formula); | |
66 | + BasicTypes::Int Calc(std::vector<std::string> lex); | |
67 | + std::vector<std::string> ProcBrackets(std::vector<std::string> lex); | |
68 | + std::string CalcBracket(std::string inBracket); | |
69 | + /*バージョン*/ | |
70 | + unsigned int | |
71 | + m_major=0, | |
72 | + m_minor=0, | |
73 | + m_build=12, | |
74 | + m_revision=30; | |
75 | + | |
76 | + | |
77 | + public: | |
78 | + Nullptr(std::string file); | |
79 | + ~Nullptr(void); | |
80 | + | |
81 | + void Work(void); | |
82 | + }; | |
83 | + } | |
84 | +} | |
\ No newline at end of file |
@@ -4,7 +4,7 @@ | ||
4 | 4 | */ |
5 | 5 | |
6 | 6 | #include"nullptr.h" |
7 | -#include"nullptrInterpreter.h" | |
7 | +#include"Interpreter.h" | |
8 | 8 | #include<regex> |
9 | 9 | #include<vector> |
10 | 10 | #include<string> |
@@ -0,0 +1,26 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +#include<string> | |
4 | + | |
5 | +#include"nullptr.h" | |
6 | +#include"Preprocessor.h" | |
7 | +#include"Interpreter.h" | |
8 | + | |
9 | +namespace VOSystemsNullptr | |
10 | +{ | |
11 | + namespace Core | |
12 | + { | |
13 | + class Module | |
14 | + { | |
15 | + private: | |
16 | + std::vector<System::Module> m_modules; | |
17 | + System::Module m_CurrentConnectModule; | |
18 | + | |
19 | + public: | |
20 | + bool Load(std::string name); | |
21 | + bool Connect(std::string name); | |
22 | + bool Run(std::string name, BasicTypes::Int* paramInt, BasicTypes::String paramString); | |
23 | + bool DisConnect(std::string name); | |
24 | + }; | |
25 | + } | |
26 | +} | |
\ No newline at end of file |
@@ -4,37 +4,78 @@ nullptr interpreter | ||
4 | 4 | */ |
5 | 5 | |
6 | 6 | #include"nullptr.h" |
7 | -#include"nullptrInterpreter.h" | |
7 | +#include"Interpreter.h" | |
8 | +#include"Module.h" | |
9 | +#include<regex> | |
8 | 10 | |
9 | 11 | using namespace std; |
10 | -using namespace VOSystemsNullptr; | |
12 | +using namespace VOSystemsNullptr::Core; | |
11 | 13 | |
12 | -bool Nullptr::ModuleInfoLoader(std::string name) | |
14 | +bool Module::Load(std::string name) | |
13 | 15 | { |
14 | 16 | string src=m_src; |
15 | 17 | string work=m_workline; |
16 | - | |
18 | + | |
19 | + System::Module module; | |
20 | + module.name=name; | |
21 | + string ident[3]={"Int","String","bool"}; | |
17 | 22 | m_src=name+".nullptrmodule"; |
18 | 23 | do{ |
19 | 24 | LineLoad(); |
25 | + if(regex_match(m_workline,regex(".+ .+(.+)"))){ | |
26 | + System::ModuleFunction mf; | |
27 | + string::iterator namestart,nameend; | |
28 | + | |
29 | + m_workline=Replace(m_workline," ",""); | |
30 | + | |
31 | + if(regex_match(m_workline,regex("bool .+(.+)"))){ | |
32 | + mf.mode=System::ReturnBool; | |
33 | + namestart=m_workline.begin()+5; | |
34 | + | |
35 | + }else if(regex_match(m_workline,regex("Int .+(.+)"))){ | |
36 | + mf.mode=System::ReturnInt; | |
37 | + namestart=m_workline.begin()+4; | |
20 | 38 | |
39 | + }else if(regex_match(m_workline,regex("String .+(.+)"))){ | |
40 | + mf.mode=System::ReturnString; | |
41 | + namestart=m_workline.begin()+7; | |
42 | + | |
43 | + } | |
44 | + nameend=m_workline.begin()+m_workline.find_first_of('('); | |
45 | + mf.name=string(namestart,nameend); | |
46 | + | |
47 | + size_t offset=0; | |
48 | + unsigned char count[3]={0}; | |
49 | + for(size_t C=0; C<3; C++){ | |
50 | + do{ | |
51 | + offset=m_workline.find(ident[C],offset+1); | |
52 | + count[C]++; | |
53 | + }while(offset==string::npos); | |
54 | + } | |
55 | + mf.ArguInt=count[0]; | |
56 | + mf.ArguString=count[1]; | |
57 | + mf.ArguBool=count[2]; | |
58 | + | |
59 | + module.modules.push_back(mf); | |
60 | + } | |
21 | 61 | }while(!m_workline.empty()); |
62 | + m_modules.push_back(module); | |
22 | 63 | |
23 | 64 | m_src=src; |
24 | 65 | m_workline=work; |
25 | 66 | } |
26 | 67 | |
27 | -bool Nullptr::ModuleConnect(std::string name) | |
68 | +bool Module::Connect(std::string name) | |
28 | 69 | { |
29 | - | |
70 | + | |
30 | 71 | } |
31 | 72 | |
32 | -bool Nullptr::ModuleRun(std::string name) | |
73 | +bool Module::Run(std::string name, BasicTypes::Int* paramInt, BasicTypes::String paramString) | |
33 | 74 | { |
34 | 75 | |
35 | 76 | } |
36 | 77 | |
37 | -bool Nullptr::ModuleDisConnect(std::string name) | |
78 | +bool Module::DisConnect(std::string name) | |
38 | 79 | { |
39 | 80 | |
40 | 81 | } |
@@ -0,0 +1,18 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +#include"nullptr.h" | |
4 | +#include"Interpreter.h" | |
5 | + | |
6 | +namespace VOSystemsNullptr | |
7 | +{ | |
8 | + namespace Core | |
9 | + { | |
10 | + class Preprocessor | |
11 | + { | |
12 | + private: | |
13 | + | |
14 | + public: | |
15 | + | |
16 | + }; | |
17 | + } | |
18 | +} | |
\ No newline at end of file |
@@ -4,7 +4,7 @@ | ||
4 | 4 | */ |
5 | 5 | |
6 | 6 | #include"nullptr.h" |
7 | -#include"nullptrInterpreter.h" | |
7 | +#include"Interpreter.h" | |
8 | 8 | #include<iostream> |
9 | 9 | #include<fstream> |
10 | 10 | #include<direct.h> |
@@ -12,6 +12,14 @@ | ||
12 | 12 | |
13 | 13 | namespace VOSystemsNullptr |
14 | 14 | { |
15 | + class Nullptr | |
16 | + { | |
17 | + private: | |
18 | + | |
19 | + public: | |
20 | + | |
21 | + }; | |
22 | + | |
15 | 23 | namespace BasicTypes |
16 | 24 | { |
17 | 25 |
@@ -92,5 +100,17 @@ namespace VOSystemsNullptr | ||
92 | 100 | std::string name; |
93 | 101 | std::vector<struct ModuleFunction> modules; |
94 | 102 | }Module; |
103 | + | |
104 | + class FileComponent | |
105 | + { | |
106 | + private: | |
107 | + size_t m_p_loaded; | |
108 | + protected: | |
109 | + std::string m_src; | |
110 | + public: | |
111 | + virtual std::string Load(void); | |
112 | + | |
113 | + }; | |
95 | 114 | } |
115 | +#define loop(count) for(size_t LoopCounter=0; LoopCounter<count; LoopCounter++) | |
96 | 116 | } |
\ No newline at end of file |
@@ -118,8 +118,10 @@ | ||
118 | 118 | </Link> |
119 | 119 | </ItemDefinitionGroup> |
120 | 120 | <ItemGroup> |
121 | + <ClInclude Include="Module.h" /> | |
121 | 122 | <ClInclude Include="nullptr.h" /> |
122 | - <ClInclude Include="nullptrInterpreter.h" /> | |
123 | + <ClInclude Include="Interpreter.h" /> | |
124 | + <ClInclude Include="Preprocessor.h" /> | |
123 | 125 | </ItemGroup> |
124 | 126 | <ItemGroup> |
125 | 127 | <ClCompile Include="BasicModule.cpp" /> |
@@ -18,7 +18,13 @@ | ||
18 | 18 | <ClInclude Include="nullptr.h"> |
19 | 19 | <Filter>ヘッダー ファイル</Filter> |
20 | 20 | </ClInclude> |
21 | - <ClInclude Include="nullptrInterpreter.h"> | |
21 | + <ClInclude Include="Preprocessor.h"> | |
22 | + <Filter>ヘッダー ファイル</Filter> | |
23 | + </ClInclude> | |
24 | + <ClInclude Include="Interpreter.h"> | |
25 | + <Filter>ヘッダー ファイル</Filter> | |
26 | + </ClInclude> | |
27 | + <ClInclude Include="Module.h"> | |
22 | 28 | <Filter>ヘッダー ファイル</Filter> |
23 | 29 | </ClInclude> |
24 | 30 | </ItemGroup> |
@@ -1,88 +0,0 @@ | ||
1 | -/* | |
2 | -nullptr Interpreter. | |
3 | -(C) 2015 VOSystems. | |
4 | -*/ | |
5 | - | |
6 | -#pragma once | |
7 | - | |
8 | -#include<vector> | |
9 | -#include<string> | |
10 | -#include<regex> | |
11 | -#include<fstream> | |
12 | -#include"nullptr.h" | |
13 | - | |
14 | -namespace VOSystemsNullptr | |
15 | -{ | |
16 | - class Nullptr | |
17 | - { | |
18 | - private: | |
19 | - std::vector<BasicTypes::IntManager> m_int;//Int変数リスト | |
20 | - std::vector<BasicTypes::String> m_string;//String変数リスト | |
21 | - std::vector<BasicTypes::Bool> m_bool;//bool変数リスト | |
22 | - System::IdentifierList m_list;//識別子リスト | |
23 | - | |
24 | - std::string m_workline;//行の内容(セミコロンの次からセミコロンまで) | |
25 | - | |
26 | - std::streamoff m_eip;//x86のEIPと同じ、命令ポインタ | |
27 | - std::string m_src;//ソースファイル名 | |
28 | - | |
29 | - void LineLoad(void);//行読み込み | |
30 | - void Extract(void);//プリプロセッサー、展開 | |
31 | - void Trim(void);//プリプロセッサー、除去 | |
32 | - | |
33 | - bool ModuleInfoLoader(std::string name); | |
34 | - bool ModuleConnect(std::string name); | |
35 | - bool ModuleRun(std::string name); | |
36 | - bool ModuleDisConnect(std::string name); | |
37 | - | |
38 | - std::vector<System::Module> m_modules; | |
39 | - System::Module m_CurrentConnectModule; | |
40 | - | |
41 | - std::string m_stdout,m_stdin,m_stderr;//標準入出力系の名前 | |
42 | - | |
43 | - std::vector<std::string> Split(const std::string &str, const std::string &delim);//文字列分割 | |
44 | - std::string Replace(std::string src, std::string before, std::string after);//文字列置き換え | |
45 | - bool Find(const std::string& str, const std::string& find);//文字列検索 | |
46 | - | |
47 | - void Screen(std::string line);//ベーシックモジュール->標準出力 | |
48 | - void Keyboard(std::string line);//ベーシックモジュール->標準入力 | |
49 | - void EScreen(std::string line);//ベーシックモジュール標準エラー出力 | |
50 | - | |
51 | - bool NewInt(std::string name, BasicTypes::Int value);//Int変数作成 | |
52 | - bool AssignInt(std::string name, BasicTypes::Int value);//Int変数代入 | |
53 | - bool GetInt(std::string name, BasicTypes::Int& target);//Int変数、値取得 | |
54 | - | |
55 | - bool NewStr(std::string name, std::string value);//String変数作成 | |
56 | - bool AssignStr(std::string name, std::string value);//String変数代入 | |
57 | - bool GetStr(std::string name, std::string& target);//String変数、値取得 | |
58 | - | |
59 | - bool NewVar(std::string line);//変数作成 | |
60 | - | |
61 | - bool If(std::string line); | |
62 | - bool For(std::string line); | |
63 | - bool While(std::string line); | |
64 | - bool Loop(std::string line); | |
65 | - bool Switch(std::string line); | |
66 | - bool Goto(std::string line); | |
67 | - bool GetBool(std::string judge); | |
68 | - | |
69 | - std::vector<std::string> Lex(std::string formula); | |
70 | - std::vector<std::string> ReplaceVar2Num(std::vector<std::string> formula); | |
71 | - BasicTypes::Int Calc(std::vector<std::string> lex); | |
72 | - std::vector<std::string> ProcBrackets(std::vector<std::string> lex); | |
73 | - std::string CalcBracket(std::string inBracket); | |
74 | - /*バージョン*/ | |
75 | - unsigned int | |
76 | - m_major=0, | |
77 | - m_minor=0, | |
78 | - m_build=12, | |
79 | - m_revision=30; | |
80 | - | |
81 | - | |
82 | - public: | |
83 | - Nullptr(std::string file); | |
84 | - ~Nullptr(void); | |
85 | - | |
86 | - void Work(void); | |
87 | - }; | |
88 | -} | |
\ No newline at end of file |
@@ -1,5 +1,5 @@ | ||
1 | 1 | #include"nullptr.h" |
2 | -#include"nullptrInterpreter.h" | |
2 | +#include"Interpreter.h" | |
3 | 3 | int main(void) |
4 | 4 | { |
5 | 5 | VOSystemsNullptr::Nullptr npr("test.nullptr"); |