• 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

修订版a2bd179d2a8663cbde84481ec3087194853b5978 (tree)
时间2015-08-07 23:27:16
作者Diverge <diverge.vosystems@gmai...>
CommiterDiverge

Log Message

演算機作成中
一部機能追加

更改概述

差异

--- /dev/null
+++ b/module.txt
@@ -0,0 +1,26 @@
1+using moduleの実装について
2+
3+モジュールはC/C++が呼び出せるライブラリ形式(動的読み込みが可能なものに限る)で実装する。
4+中には必ず
5+open(void)
6+close(void)
7+run関数群(後述)
8+を入れる。
9+
10+
11+run関数群
12+実行される関数は必ずしも引数が一つづつとは限らないので、ポインタを使い返り値の型の違いで関数を分ける。
13+幸いなことに、nullptrには整数型が複数個ないため実装の数を減らすことができる。
14+bool runRB(std::string, Int*, String*, bool*);
15+Int runRI(std::string, Int*, String*, bool*);
16+String runRS(std::string, Int*, String*, bool*);
17+最初の引数std::stringは機能の名前になる
18+
19+モジュールファイルには各機能に必要な引数の個数と返り値の型を書いておく。
20+bool func(Int 2, String 0, bool 0);
21+上記のような機能定義の場合、呼び出される関数はrunRBとなり
22+runRB("func", Int*, nullptr, nullptr);
23+となる。
24+
25+同時に読み込むDLLは一つまでとする。(同じ名前の関数ができてしまうため。)
26+読み込んだら初めにopen、終わったらcloseを呼びリンクを解く
\ No newline at end of file
Binary files a/nullptr.sdf and b/nullptr.sdf differ
--- a/nullptr/BasicModule.cpp
+++ b/nullptr/BasicModule.cpp
@@ -59,5 +59,27 @@ void Nullptr::Keyboard(std::string line)
5959
6060 void Nullptr::EScreen(std::string line)
6161 {
62+ vector<string> str=Split(line,"<<<");
6263
64+ for(size_t C=1; C<str.size(); C++){
65+ if(regex_match(str[C],regex("\".+\""))){
66+ cerr<<Replace(str[C],"\"","");
67+ }else if(str[C]=="endl"){
68+ cerr<<endl;
69+ }else if(str[C]=="flush"){
70+ cerr<<flush;
71+ }else if(regex_match(str[C],regex("\\d+"))){
72+ cerr<<stoi(str[C]);
73+ }else{
74+ BasicTypes::Int ull;
75+ if(GetInt(str[C],ull)){
76+ cerr<<BasicTypes::IntManager(to_string(0),ull)(ull,'d');
77+ }else{
78+ string s;
79+ if(GetStr(str[C],s)){
80+ cerr<<s;
81+ }
82+ }
83+ }
84+ }
6385 }
\ No newline at end of file
--- a/nullptr/ControlManager.cpp
+++ b/nullptr/ControlManager.cpp
@@ -58,5 +58,123 @@ bool Nullptr::GetBool(string judge)
5858
5959 }
6060 }
61-TrueEnd:
61+}
62+
63+vector<string> Nullptr::Lex(string formula)
64+{
65+ vector<string> form;
66+ formula=Replace(formula," ","");
67+ smatch result;
68+
69+ for(size_t C=0; C<formula.size(); C++){
70+ if(regex_search(formula,result,regex("\\d+"))){
71+ size_t diff=result.end()-result.begin();
72+ string num(result.begin(),result.end());
73+ form.push_back(num);
74+ C+=diff;
75+ }else{
76+ switch(formula[C]){
77+ case '+':
78+ case '-':
79+ if(C+1<formula.size()){
80+ if(formula[C+1]==formula[C]){
81+ form.push_back({formula[C++],formula[C],'\0'});
82+ break;
83+ }
84+ }
85+ case '*':
86+ case '/':
87+ case '%':
88+ form.push_back({formula[C],'\0'});
89+ break;
90+
91+ default:
92+ char* varname=new char[formula.size()];
93+ varname[0]=formula[C];
94+ for(size_t varpoint=0; varpoint<formula.size(); varpoint++){
95+ if(isalnum(formula[C+varpoint])){
96+ varname[varpoint]=formula[C+varpoint];
97+ }else{
98+ C+=varpoint;
99+ break;
100+ }
101+ }
102+ form.push_back(varname);
103+ break;
104+ }
105+ }
106+
107+ }
108+}
109+
110+vector<std::string> Nullptr::ReplaceVar2Num(vector<string> formula)
111+{
112+ BasicTypes::Int intb;
113+ vector<string> lex;
114+
115+ for(size_t C=0; C<formula.size(); C++){
116+ if(isalpha(formula[C][0])){
117+ GetInt(formula[C],intb);
118+ lex.push_back(BasicTypes::IntManager()(intb,'d'));
119+ }else{
120+ lex.push_back(formula[C]);
121+ }
122+ }
123+ return lex;
124+}
125+
126+BasicTypes::Int Nullptr::Calc(vector<string> lex)
127+{
128+ BasicTypes::Int intd;
129+}
130+
131+std::vector<std::string> Nullptr::ProcBrackets(std::vector<std::string> lex)
132+{
133+ vector<string>::iterator open,close;
134+ vector<string> lexed;
135+
136+ for(size_t C=0; C<lex.size(); C++){
137+ if(lex[C]=="("){
138+ open=lex.begin()+C;
139+ }else if(lex[C]==")"){
140+ close=lex.begin()+C;
141+ lexed.push_back(CalcBracket(string(open,close)));
142+ }else{
143+ lexed.push_back(lex[C]);
144+ }
145+ }
146+}
147+
148+std::string Nullptr::CalcBracket(std::string inBracket)
149+{
150+ vector<BasicTypes::Int> num;
151+ bool minus=false;
152+ for(size_t C=0; C<inBracket.size(); C++){
153+ switch(inBracket[C]){
154+ case '+':
155+
156+ break;
157+ case '-':
158+
159+ break;
160+ case '*':
161+
162+ break;
163+ case '/':
164+
165+ break;
166+ case '%':
167+
168+ break;
169+
170+ default:
171+ char* n=new char[inBracket.size()-C];
172+ for(size_t c=C; c<inBracket.size(); c++){
173+ if(!isdigit(inBracket[c]))break;
174+ n[c-C]=inBracket[c];
175+ }
176+ num.push_back({!minus,stoull(n)});
177+ break;
178+ }
179+ }
62180 }
\ 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/vc140.idb and b/nullptr/Debug/vc140.idb differ
--- a/nullptr/int.cpp
+++ b/nullptr/int.cpp
@@ -16,16 +16,7 @@ void IntManager::operator=(Int data)
1616
1717 Int IntManager::operator+(Int i)
1818 {
19- Int tmp;
20-
21- if(i.positive==this->m_data.positive){
22- tmp.data=i.data + this->m_data.data;
23- tmp.positive=i.positive;
24- }else{
25- tmp.data=(i.data > this->m_data.data ? +1 : -1)*(i.data - this->m_data.data);
26- tmp.positive=(i.data > this->m_data.data ? true : false);
27- }
28- return tmp;
19+ return m_data+i;
2920 }
3021
3122 std::string IntManager::operator()(Int i, char type)
@@ -56,36 +47,22 @@ std::string IntManager::operator()(Int i, char type)
5647
5748 Int IntManager::operator-(Int i)
5849 {
59- Int tmp;
60- tmp=this->operator+({i.data,!i.positive});
61- return tmp;
50+ return m_data-i;
6251 }
6352
6453 Int IntManager::operator*(Int i)
6554 {
66- Int tmp;
67-
68- tmp.data=i.data*this->m_data.data;
69- tmp.positive=(i.positive==false || this->m_data.positive==false ? false : true);
70- return tmp;
55+ return m_data*i;
7156 }
7257
7358 Int IntManager::operator/(Int i)
7459 {
75- Int tmp;
76-
77- tmp.data=this->m_data.data/i.data;
78- tmp.positive=(i.positive==false || this->m_data.positive==false ? false : true);
79- return tmp;
60+ return m_data/i;
8061 }
8162
8263 Int IntManager::operator%(Int i)
8364 {
84- Int tmp;
85-
86- tmp.data=this->m_data.data%i.data;
87- tmp.positive=(i.positive==false || this->m_data.positive==false ? false : true);
88- return tmp;
65+ return m_data%i;
8966 }
9067
9168 Int IntManager::operator()(void)
@@ -95,7 +72,7 @@ Int IntManager::operator()(void)
9572
9673 std::string IntManager::operator()(char type)
9774 {
98- string str=IntManager("tmp",this->m_data)(this->m_data,type);
75+ string str=IntManager()(this->m_data,type);
9976 return str;
10077 }
10178
@@ -137,4 +114,53 @@ Int IntManager::GetValue(void)
137114 std::string IntManager::GetName(void)
138115 {
139116 return m_name;
140-}
\ No newline at end of file
117+}
118+
119+
120+Int VOSystemsNullptr::BasicTypes::operator+(Int p1,Int p2)
121+{
122+ Int tmp;
123+
124+ if(p2.positive==p1.positive){
125+ tmp.data=p2.data + p1.data;
126+ tmp.positive=p2.positive;
127+ }else{
128+ tmp.data=(p2.data > p1.data ? +1 : -1)*(p2.data - p1.data);
129+ tmp.positive=(p2.data > p1.data ? true : false);
130+ }
131+ return tmp;
132+}
133+
134+Int VOSystemsNullptr::BasicTypes::operator-(Int p1, Int p2)
135+{
136+ Int tmp={p2.data,!p2.positive};
137+ tmp=p1+tmp;
138+ return tmp;
139+}
140+
141+Int VOSystemsNullptr::BasicTypes::operator*(Int p1, Int p2)
142+{
143+ Int tmp;
144+
145+ tmp.data=p1.data*p2.data;
146+ tmp.positive=(p1.positive==false || p2.positive==false ? false : true);
147+ return tmp;
148+}
149+
150+Int VOSystemsNullptr::BasicTypes::operator/(Int p1, Int p2)
151+{
152+ Int tmp;
153+
154+ tmp.data=p1.data/p2.data;
155+ tmp.positive=(p1.positive==false || p2.positive==false ? false : true);
156+ return tmp;
157+}
158+
159+Int VOSystemsNullptr::BasicTypes::operator%(Int p1, Int p2)
160+{
161+ Int tmp;
162+
163+ tmp.data=p1.data%p2.data;
164+ tmp.positive=(p1.positive==false || p2.positive==false ? false : true);
165+ return tmp;
166+}
--- a/nullptr/nullptr.h
+++ b/nullptr/nullptr.h
@@ -28,7 +28,7 @@ namespace VOSystemsNullptr
2828
2929 public:
3030 IntManager(std::string name, Int data) :m_name(name),m_data(data) {};
31-
31+ IntManager(void){};
3232 void operator=(Int data);
3333
3434 BasicTypes::Int operator+(BasicTypes::Int i);
@@ -50,6 +50,12 @@ namespace VOSystemsNullptr
5050 std::string GetName(void);
5151 };
5252
53+ BasicTypes::Int operator+(BasicTypes::Int,BasicTypes::Int);
54+ BasicTypes::Int operator-(BasicTypes::Int,BasicTypes::Int);
55+ BasicTypes::Int operator*(BasicTypes::Int,BasicTypes::Int);
56+ BasicTypes::Int operator/(BasicTypes::Int,BasicTypes::Int);
57+ BasicTypes::Int operator%(BasicTypes::Int,BasicTypes::Int);
58+
5359 typedef struct _String{
5460 std::string name;
5561 std::string data;
--- a/nullptr/nullptrInterpreter.h
+++ b/nullptr/nullptrInterpreter.h
@@ -57,6 +57,11 @@ namespace VOSystemsNullptr
5757 bool Goto(std::string line);
5858 bool GetBool(std::string judge);
5959
60+ std::vector<std::string> Lex(std::string formula);
61+ std::vector<std::string> ReplaceVar2Num(std::vector<std::string> formula);
62+ BasicTypes::Int Calc(std::vector<std::string> lex);
63+ std::vector<std::string> ProcBrackets(std::vector<std::string> lex);
64+ std::string CalcBracket(std::string inBracket);
6065 /*バージョン*/
6166 unsigned int
6267 m_major=0,