• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

自作言語nullptrのインタープリターです。


Commit MetaInfo

修訂1e15288bc2b347085ca08395a65b88f366d5b6c9 (tree)
時間2015-08-07 00:25:26
作者Diverge <diverge.vosystems@gmai...>
CommiterDiverge

Log Message

ソース分割
モジュールの読み込みについて決定(未実装)
制御構文の実装開始

Change Summary

差異

Binary files a/nullptr.sdf and b/nullptr.sdf differ
--- /dev/null
+++ b/nullptr/BasicModule.cpp
@@ -0,0 +1,63 @@
1+/*
2+ nullptr interpreter
3+ (C) 2015 VOSystems.
4+*/
5+
6+#include"nullptr.h"
7+#include"nullptrInterpreter.h"
8+#include<iostream>
9+#include<fstream>
10+#include<direct.h>
11+#include<cctype>
12+#include<algorithm>
13+#include<Windows.h>
14+
15+using namespace VOSystemsNullptr;
16+using namespace std;
17+
18+void Nullptr::Screen(std::string line)
19+{
20+ vector<string> str=Split(line,"<<<");
21+
22+ for(size_t C=1; C<str.size(); C++){
23+ if(regex_match(str[C],regex("\".+\""))){
24+ cout<<Replace(str[C],"\"","");
25+ }else if(str[C]=="endl"){
26+ cout<<endl;
27+ }else if(str[C]=="flush"){
28+ cout<<flush;
29+ }else if(regex_match(str[C],regex("\\d+"))){
30+ cout<<stoi(str[C]);
31+ }else{
32+ BasicTypes::Int ull;
33+ if(GetInt(str[C],ull)){
34+ cout<<BasicTypes::IntManager(to_string(0),ull)(ull,'d');
35+ }else{
36+ string s;
37+ if(GetStr(str[C],s)){
38+ cout<<s;
39+ }
40+ }
41+ }
42+ }
43+}
44+
45+void Nullptr::Keyboard(std::string line)
46+{
47+ vector<string> str=Split(line,">>>");
48+ for(size_t C=1; C<str.size(); C++){
49+ string in;
50+ cin>>in;
51+ if(all_of(in.cbegin(),in.cend(),isdigit)){
52+ BasicTypes::Int ints={stoll(in)<0 ? -stoll(in) : stoull(in),stoll(in)>=0};
53+ AssignInt(str[C],ints);
54+ }else{
55+ AssignStr(str[C],in);
56+ }
57+ }
58+}
59+
60+void Nullptr::EScreen(std::string line)
61+{
62+
63+}
\ No newline at end of file
--- /dev/null
+++ b/nullptr/ControlManager.cpp
@@ -0,0 +1,62 @@
1+/*
2+ nullptr interpreter
3+ (C) 2015 VOSystems.
4+*/
5+
6+#include"nullptr.h"
7+#include"nullptrInterpreter.h"
8+#include<iostream>
9+#include<fstream>
10+#include<direct.h>
11+#include<cctype>
12+#include<algorithm>
13+#include<Windows.h>
14+
15+using namespace VOSystemsNullptr;
16+using namespace std;
17+
18+bool Nullptr::If(string line)
19+{
20+ vector<string> str=Split(line,"{");//if(judge) { sentence;
21+ vector<string> ctrl=Split(str[0],"(");//if ( judge)
22+ string judge=Replace(ctrl[1],")","");//judge )
23+
24+}
25+
26+bool Nullptr::For(string line)
27+{
28+
29+}
30+
31+bool Nullptr::While(string line)
32+{
33+
34+}
35+
36+bool Nullptr::Loop(string line)
37+{
38+
39+}
40+
41+bool Nullptr::Switch(string line)
42+{
43+
44+}
45+
46+bool Nullptr::Goto(string line)
47+{
48+
49+}
50+
51+bool Nullptr::GetBool(string judge)
52+{
53+ vector<string> andSplit=Split(judge,"&&");
54+ for(size_t C=0; C<andSplit.size(); C++){
55+ vector<string> orSplit=Split(andSplit[C],"||");
56+
57+ for(size_t c=0; c<orSplit.size(); c++){
58+
59+ }
60+ }
61+TrueEnd:
62+}
\ No newline at end of file
Binary files a/nullptr/Debug/nullptr.tlog/CL.command.1.tlog and b/nullptr/Debug/nullptr.tlog/CL.command.1.tlog differ
Binary files a/nullptr/Debug/nullptr.tlog/CL.read.1.tlog and b/nullptr/Debug/nullptr.tlog/CL.read.1.tlog differ
Binary files a/nullptr/Debug/nullptr.tlog/CL.write.1.tlog and b/nullptr/Debug/nullptr.tlog/CL.write.1.tlog differ
Binary files a/nullptr/Debug/nullptr.tlog/link.command.1.tlog and b/nullptr/Debug/nullptr.tlog/link.command.1.tlog differ
Binary files a/nullptr/Debug/nullptr.tlog/link.read.1.tlog and b/nullptr/Debug/nullptr.tlog/link.read.1.tlog differ
Binary files a/nullptr/Debug/nullptr.tlog/link.write.1.tlog and b/nullptr/Debug/nullptr.tlog/link.write.1.tlog differ
Binary files a/nullptr/Debug/vc140.idb and b/nullptr/Debug/vc140.idb differ
--- /dev/null
+++ b/nullptr/ManageVar.cpp
@@ -0,0 +1,113 @@
1+/*
2+ nullptr interpreter
3+ (C) 2015 VOSystems.
4+*/
5+
6+#include"nullptr.h"
7+#include"nullptrInterpreter.h"
8+#include<regex>
9+#include<vector>
10+#include<string>
11+
12+using namespace std;
13+using namespace VOSystemsNullptr;
14+
15+bool Nullptr::NewVar(std::string line)
16+{
17+ regex_replace(line,regex(" +"),"\t");
18+ line=Replace(line,"\t"," ");
19+ vector<string> str=Split(line," ");
20+
21+ unsigned long long type=0;
22+
23+ for(size_t C=0; C<str.size(); C++){
24+ if(str[C]=="Int"){
25+ C++;
26+ vector<string> s=Split(str[C],"=");
27+ if(s.size()>0){
28+ string name=s[0];
29+ BasicTypes::Int intd={0,true};
30+
31+ if(s.size()>1){
32+ intd.data=stoll(Replace(s[1],"\"",""));
33+ intd.positive=(intd.data>=0);
34+ }
35+ return NewInt(name,intd);
36+ }
37+
38+ }else if(str[C]=="String"){
39+ C++;
40+ vector<string> s=Split(str[C],"=");
41+ if(s.size()>0){
42+ string name=s[0];
43+ string value;
44+ if(s.size()>1){
45+ value=Replace(s[1],"\"","");
46+ }
47+ return NewStr(name,value);
48+ }
49+ }
50+
51+ }
52+ return false;
53+}
54+
55+bool Nullptr::NewInt(std::string name, BasicTypes::Int value)
56+{
57+ BasicTypes::IntManager inte(name,value);
58+ m_int.push_back(inte);
59+ return true;
60+}
61+
62+bool Nullptr::AssignInt(std::string name, BasicTypes::Int value)
63+{
64+ for(size_t C=0; C<m_int.size(); C++){
65+ if(m_int[C].GetName()==name){
66+ m_int[C]=value;
67+ return true;
68+ }
69+ }
70+ return false;
71+}
72+
73+bool Nullptr::GetInt(std::string name, BasicTypes::Int& target)
74+{
75+ for(size_t C=0; C<m_int.size(); C++){
76+ if(m_int[C].GetName()==name){
77+ target=m_int[C]();
78+ return true;
79+ }
80+ }
81+ return false;
82+}
83+
84+bool Nullptr::NewStr(std::string name, std::string value)
85+{
86+ BasicTypes::String str;
87+ str.data=value;
88+ str.name=name;
89+ m_string.push_back(str);
90+ return true;
91+}
92+
93+bool Nullptr::AssignStr(std::string name, std::string value)
94+{
95+ for(size_t C=0; C<m_string.size(); C++){
96+ if(m_string[C].name==name){
97+ m_string[C].data=value;
98+ return true;
99+ }
100+ }
101+ return false;
102+}
103+
104+bool Nullptr::GetStr(std::string name, std::string& target)
105+{
106+ for(size_t C=0; C<m_string.size(); C++){
107+ if(m_string[C].name==name){
108+ target=m_string[C].data;
109+ return true;
110+ }
111+ }
112+ return false;
113+}
\ No newline at end of file
--- a/nullptr/NullptrTmp/Extracted.nullptr
+++ b/nullptr/NullptrTmp/Extracted.nullptr
@@ -1,5 +1,5 @@
11 screen<<<"Check"<<<endl;
2-screen<<<123<<<endl;理??c
2+screen<<<123<<<endl;理?
33 screen<<<"Hello,World!!"<<<endl;
44 screen<<<"HW"<<<flush;
55 screen<<<"HWHW"<<<endl;
--- a/nullptr/nullptr.cpp
+++ b/nullptr/nullptr.cpp
@@ -4,6 +4,7 @@
44 */
55
66 #include"nullptr.h"
7+#include"nullptrInterpreter.h"
78 #include<iostream>
89 #include<fstream>
910 #include<direct.h>
@@ -14,7 +15,8 @@
1415 using namespace VOSystemsNullptr;
1516 using namespace std;
1617
17-vector<string> split(const string &str, const string &delim) {
18+vector<string> Nullptr::Split(const string &str, const string &delim)
19+{
1820 vector<string> res;
1921 size_t current = 0, found, delimlen = delim.size();
2022 while ((found = str.find(delim, current)) != string::npos) {
@@ -25,7 +27,7 @@ vector<string> split(const string &str, const string &delim) {
2527 return res;
2628 }
2729
28-std::string Replace(std::string src, std::string before, std::string after)
30+std::string Nullptr::Replace(std::string src, std::string before, std::string after)
2931 {
3032 std::string::size_type Pos(src.find(before));
3133
@@ -37,7 +39,7 @@ std::string Replace(std::string src, std::string before, std::string after)
3739 return src;
3840 }
3941
40-bool Find(const string& str, const string& find)
42+bool Nullptr::Find(const string& str, const string& find)
4143 {
4244 return(str.find(find) != string::npos);
4345 }
@@ -96,7 +98,7 @@ void Nullptr::Extract(void)
9698 id=Replace(id,"\t","");
9799 id=Replace(id," ","");
98100 id=Replace(id,";","");
99- vector<string> ids=split(id,"->");
101+ vector<string> ids=Split(id,"->");
100102 if(id.size()>1){
101103 if(ids[0]=="stdin"){
102104 m_stdin=ids[1];
@@ -147,46 +149,6 @@ void Nullptr::Work(void)
147149 }
148150 }
149151
150-bool Nullptr::NewVar(std::string line)
151-{
152- regex_replace(line,regex(" +"),"\t");
153- line=Replace(line,"\t"," ");
154- vector<string> str=split(line," ");
155-
156- unsigned long long type=0;
157-
158- for(size_t C=0; C<str.size(); C++){
159- if(str[C]=="Int"){
160- C++;
161- vector<string> s=split(str[C],"=");
162- if(s.size()>0){
163- string name=s[0];
164- BasicTypes::Int intd={0,true};
165-
166- if(s.size()>1){
167- intd.data=stoll(Replace(s[1],"\"",""));
168- intd.positive=(intd.data>=0);
169- }
170- return NewInt(name,intd);
171- }
172-
173- }else if(str[C]=="String"){
174- C++;
175- vector<string> s=split(str[C],"=");
176- if(s.size()>0){
177- string name=s[0];
178- string value;
179- if(s.size()>1){
180- value=Replace(s[1],"\"","");
181- }
182- return NewStr(name,value);
183- }
184- }
185-
186- }
187- return false;
188-}
189-
190152 void Nullptr::LineLoad(void)
191153 {
192154 ifstream fin(m_src);
@@ -206,109 +168,3 @@ void Nullptr::LineLoad(void)
206168 fin.close();
207169 }
208170
209-bool Nullptr::NewInt(std::string name, BasicTypes::Int value)
210-{
211- BasicTypes::IntManager inte(name,value);
212- m_int.push_back(inte);
213- return true;
214-}
215-
216-bool Nullptr::AssignInt(std::string name, BasicTypes::Int value)
217-{
218- for(size_t C=0; C<m_int.size(); C++){
219- if(m_int[C].GetName()==name){
220- m_int[C]=value;
221- return true;
222- }
223- }
224- return false;
225-}
226-
227-bool Nullptr::GetInt(std::string name, BasicTypes::Int& target)
228-{
229- for(size_t C=0; C<m_int.size(); C++){
230- if(m_int[C].GetName()==name){
231- target=m_int[C]();
232- return true;
233- }
234- }
235- return false;
236-}
237-
238-bool Nullptr::NewStr(std::string name, std::string value)
239-{
240- BasicTypes::String str;
241- str.data=value;
242- str.name=name;
243- m_string.push_back(str);
244- return true;
245-}
246-
247-bool Nullptr::AssignStr(std::string name, std::string value)
248-{
249- for(size_t C=0; C<m_string.size(); C++){
250- if(m_string[C].name==name){
251- m_string[C].data=value;
252- return true;
253- }
254- }
255- return false;
256-}
257-
258-bool Nullptr::GetStr(std::string name, std::string& target)
259-{
260- for(size_t C=0; C<m_string.size(); C++){
261- if(m_string[C].name==name){
262- target=m_string[C].data;
263- return true;
264- }
265- }
266- return false;
267-}
268-
269-void Nullptr::Screen(std::string line)
270-{
271- vector<string> str=split(line,"<<<");
272-
273- for(size_t C=1; C<str.size(); C++){
274- if(regex_match(str[C],regex("\".+\""))){
275- cout<<Replace(str[C],"\"","");
276- }else if(str[C]=="endl"){
277- cout<<endl;
278- }else if(str[C]=="flush"){
279- cout<<flush;
280- }else if(regex_match(str[C],regex("\\d+"))){
281- cout<<stoi(str[C]);
282- }else{
283- BasicTypes::Int ull;
284- if(GetInt(str[C],ull)){
285- cout<<BasicTypes::IntManager(to_string(0),ull)(ull,'d');
286- }else{
287- string s;
288- if(GetStr(str[C],s)){
289- cout<<s;
290- }
291- }
292- }
293- }
294-}
295-
296-void Nullptr::Keyboard(std::string line)
297-{
298- vector<string> str=split(line,">>>");
299- for(size_t C=1; C<str.size(); C++){
300- string in;
301- cin>>in;
302- if(all_of(in.cbegin(),in.cend(),isdigit)){
303- BasicTypes::Int ints={stoll(in)<0 ? -stoll(in) : stoull(in),stoll(in)>=0};
304- AssignInt(str[C],ints);
305- }else{
306- AssignStr(str[C],in);
307- }
308- }
309-}
310-
311-void Nullptr::EScreen(std::string line)
312-{
313-
314-}
\ No newline at end of file
--- a/nullptr/nullptr.h
+++ b/nullptr/nullptr.h
@@ -26,7 +26,6 @@ namespace VOSystemsNullptr
2626 BasicTypes::Int m_data;
2727 std::string m_name;
2828
29-
3029 public:
3130 IntManager(std::string name, Int data) :m_name(name),m_data(data) {};
3231
@@ -56,6 +55,10 @@ namespace VOSystemsNullptr
5655 std::string data;
5756 }String;
5857
58+ typedef struct _Bool{
59+ bool data;
60+ std::string name;
61+ }Bool;
5962 }
6063
6164 namespace System{
@@ -66,51 +69,4 @@ namespace VOSystemsNullptr
6669
6770 typedef std::vector<Identifier> IdentifierList;
6871 }
69-
70- class Nullptr
71- {
72- private:
73- std::vector<BasicTypes::IntManager> m_int;
74- std::vector<BasicTypes::String> m_string;
75- System::IdentifierList m_list;
76-
77- std::string m_workline;
78-
79- std::streamoff m_eip;
80- std::string m_src;
81-
82- System::IdentifierList m_idlist;
83-
84- void LineLoad(void);
85- void Extract(void);
86-
87- std::string m_stdout,m_stdin,m_stderr;
88-
89- void Screen(std::string line);
90- void Keyboard(std::string line);
91- void EScreen(std::string line);
92-
93- bool NewInt(std::string name, BasicTypes::Int value);
94- bool AssignInt(std::string name, BasicTypes::Int value);
95- bool GetInt(std::string name, BasicTypes::Int& target);
96-
97- bool NewStr(std::string name, std::string value);
98- bool AssignStr(std::string name, std::string value);
99- bool GetStr(std::string name, std::string& target);
100-
101- bool NewVar(std::string line);
102-
103- unsigned int
104- m_major=0,
105- m_minor=0,
106- m_build=12,
107- m_revision=30;
108-
109-
110- public:
111- Nullptr(std::string file);
112- ~Nullptr(void);
113-
114- void Work(void);
115- };
11672 }
\ No newline at end of file
--- a/nullptr/nullptr.vcxproj
+++ b/nullptr/nullptr.vcxproj
@@ -119,9 +119,13 @@
119119 </ItemDefinitionGroup>
120120 <ItemGroup>
121121 <ClInclude Include="nullptr.h" />
122+ <ClInclude Include="nullptrInterpreter.h" />
122123 </ItemGroup>
123124 <ItemGroup>
125+ <ClCompile Include="BasicModule.cpp" />
126+ <ClCompile Include="ControlManager.cpp" />
124127 <ClCompile Include="int.cpp" />
128+ <ClCompile Include="ManageVar.cpp" />
125129 <ClCompile Include="nullptr.cpp" />
126130 <ClCompile Include="open.cpp" />
127131 </ItemGroup>
--- a/nullptr/nullptr.vcxproj.filters
+++ b/nullptr/nullptr.vcxproj.filters
@@ -18,6 +18,9 @@
1818 <ClInclude Include="nullptr.h">
1919 <Filter>ヘッダー ファイル</Filter>
2020 </ClInclude>
21+ <ClInclude Include="nullptrInterpreter.h">
22+ <Filter>ヘッダー ファイル</Filter>
23+ </ClInclude>
2124 </ItemGroup>
2225 <ItemGroup>
2326 <ClCompile Include="nullptr.cpp">
@@ -29,6 +32,15 @@
2932 <ClCompile Include="int.cpp">
3033 <Filter>ソース ファイル</Filter>
3134 </ClCompile>
35+ <ClCompile Include="ManageVar.cpp">
36+ <Filter>ソース ファイル</Filter>
37+ </ClCompile>
38+ <ClCompile Include="BasicModule.cpp">
39+ <Filter>ソース ファイル</Filter>
40+ </ClCompile>
41+ <ClCompile Include="ControlManager.cpp">
42+ <Filter>ソース ファイル</Filter>
43+ </ClCompile>
3244 </ItemGroup>
3345 <ItemGroup>
3446 <None Include="iostream.nullptrmodule" />
--- /dev/null
+++ b/nullptr/nullptrInterpreter.h
@@ -0,0 +1,74 @@
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+
32+ std::string m_stdout,m_stdin,m_stderr;//標準入出力系の名前
33+
34+ std::vector<std::string> Split(const std::string &str, const std::string &delim);//文字列分割
35+ std::string Replace(std::string src, std::string before, std::string after);//文字列置き換え
36+ bool Find(const std::string& str, const std::string& find);//文字列検索
37+
38+ void Screen(std::string line);//ベーシックモジュール->標準出力
39+ void Keyboard(std::string line);//ベーシックモジュール->標準入力
40+ void EScreen(std::string line);//ベーシックモジュール標準エラー出力
41+
42+ bool NewInt(std::string name, BasicTypes::Int value);//Int変数作成
43+ bool AssignInt(std::string name, BasicTypes::Int value);//Int変数代入
44+ bool GetInt(std::string name, BasicTypes::Int& target);//Int変数、値取得
45+
46+ bool NewStr(std::string name, std::string value);//String変数作成
47+ bool AssignStr(std::string name, std::string value);//String変数代入
48+ bool GetStr(std::string name, std::string& target);//String変数、値取得
49+
50+ bool NewVar(std::string line);//変数作成
51+
52+ bool If(std::string line);
53+ bool For(std::string line);
54+ bool While(std::string line);
55+ bool Loop(std::string line);
56+ bool Switch(std::string line);
57+ bool Goto(std::string line);
58+ bool GetBool(std::string judge);
59+
60+ /*バージョン*/
61+ unsigned int
62+ m_major=0,
63+ m_minor=0,
64+ m_build=12,
65+ m_revision=30;
66+
67+
68+ public:
69+ Nullptr(std::string file);
70+ ~Nullptr(void);
71+
72+ void Work(void);
73+ };
74+}
\ No newline at end of file
--- a/nullptr/open.cpp
+++ b/nullptr/open.cpp
@@ -1,5 +1,5 @@
11 #include"nullptr.h"
2-
2+#include"nullptrInterpreter.h"
33 int main(void)
44 {
55 VOSystemsNullptr::Nullptr npr("test.nullptr");