• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

N88BASICが簡単に動くインタープリタを目指します。


コミットメタ情報

リビジョン27 (tree)
日時2018-10-02 17:45:56
作者bellyoshi

ログメッセージ

変更サマリ

差分

--- trunk/csmock/WindowsFormsApp1/getToken/compile.cs (revision 26)
+++ trunk/csmock/WindowsFormsApp1/getToken/compile.cs (revision 27)
@@ -73,13 +73,10 @@
7373 {
7474 string var_name;
7575 next();
76- Console.Write("for(");
7776 if(nextToken.TokenType == TokenType.identifier)
7877 {
7978 //todo:変数表の処理は後回しとする。
80- Console.Write("var ");
8179 var_name = nextToken.src_str;
82- Console.Write(nextToken.src_str);
8380 }
8481 else
8582 {
@@ -87,18 +84,13 @@
8784 return;
8885 }
8986 next();
90- if(nextToken.TokenType == TokenType.Equal)
91- {
92- Console.Write(" = ");
93- }
94- else
95- {
87+ if(nextToken.TokenType != TokenType.Equal) {
9688 syntaxError();
9789 return;
9890 }
9991 next();
100- expression();
101- if(nextToken.TokenType == TokenType.ab_to)
92+ var init_value = getExpression();
93+ if (nextToken.TokenType == TokenType.ab_to)
10294 {
10395 next();
10496 }
@@ -107,9 +99,10 @@
10799 syntaxError();
108100 return;
109101 }
110- Console.Write($";{var_name} <=");//todo step -1の処理
111- expression();
112- Console.Write($";{var_name}++)");
102+ var to_value = getExpression();
103+
104+ //todo step -1の処理
105+ Console.Write($"for(var {var_name} = {init_value};{var_name} <= {to_value}; {var_name}++)");
113106 Console.WriteLine("{");
114107 while (nextToken.TokenType != TokenType.ab_next)
115108 {
@@ -124,7 +117,6 @@
124117 public void s_abn88_Line()
125118 {
126119 next();
127- Console.Write("n88.Line(");
128120 if (nextToken.TokenType == TokenType.Lparen)
129121 {
130122 next();
@@ -134,10 +126,9 @@
134126 syntaxError();
135127 return;
136128 }
137- expression();//pt_start_x
129+ var sx = getExpression();//pt_start_x
138130 if (nextToken.TokenType == TokenType.Comma)
139131 {
140- Console.Write(",");
141132 next();
142133 }
143134 else
@@ -145,10 +136,9 @@
145136 syntaxError();
146137 return;
147138 }
148- expression();//pt_start_y
139+ var sy = getExpression();//pt_start_y
149140 if(nextToken.TokenType == TokenType.Rparen)
150141 {
151- Console.Write(",");
152142 next();
153143 }
154144 else
@@ -174,10 +164,9 @@
174164 syntaxError();
175165 return;
176166 }
177- expression();//pt_end_x
167+ var ex = getExpression();//pt_end_x
178168 if(nextToken.TokenType == TokenType.Comma)
179169 {
180- Console.WriteLine(",");
181170 next();
182171 }
183172 else
@@ -185,7 +174,7 @@
185174 syntaxError();
186175 return;
187176 }
188- expression();//pt_end_y
177+ var ey = getExpression();//pt_end_y
189178 if (nextToken.TokenType == TokenType.Rparen)
190179 {
191180 next();
@@ -195,12 +184,15 @@
195184 syntaxError();
196185 return;
197186 }
187+ Console.Write($"n88.Line({sx},{sy},{ex},{ey}");
188+ string col,col2;
198189 if (nextToken.TokenType == TokenType.Comma)
199190 {
200191 next();
201192 Console.Write(",");
202193 if(nextToken.TokenType != TokenType.Comma) {
203- expression();//color
194+ col = getExpression();//color
195+ Console.Write(col);
204196 next();
205197 }
206198 }
@@ -226,15 +218,26 @@
226218 }
227219 if (nextToken.TokenType == TokenType.Comma)
228220 {
229- Console.Write(",");
230221 next();
231- expression();//color2
222+ col2 = getExpression();//color2
232223 next();
224+ Console.Write($",{col2}");
233225 }
234226 line_end:
235227 Console.WriteLine(");");
236228
237229 }
230+ private string expressionStr;
231+ string getExpression()
232+ {
233+ expressionStr = "";
234+ expression();
235+ return expressionStr;
236+ }
237+ void codeGene(string code)
238+ {
239+ expressionStr += code;
240+ }
238241 void expression()
239242 {
240243 TokenType t = nextToken.TokenType;
@@ -245,7 +248,7 @@
245248 if (t == TokenType.Minus)
246249 {
247250 //gencode neg
248- Console.Write("-");
251+ codeGene("-");
249252 }
250253 }
251254 else
@@ -258,12 +261,12 @@
258261 if (t == TokenType.Minus)
259262 {
260263 //gencode sub
261- Console.Write("-");
264+ codeGene("-");
262265 }
263266 else
264267 {
265268 //gencode add
266- Console.Write("+");
269+ codeGene("+");
267270 }
268271 next();
269272 term();
@@ -279,12 +282,12 @@
279282 if (t == TokenType.Mult)
280283 {
281284 //gencode mul
282- Console.Write("*");
285+ codeGene("*");
283286 }
284287 else
285288 {
286289 //gencode div
287- Console.Write("/");
290+ codeGene("/");
288291 }
289292 next();
290293 factor();
@@ -295,16 +298,16 @@
295298 {
296299 if (nextToken.TokenType == TokenType.identifier)
297300 {
298- Console.Write(nextToken.src_str);
301+ codeGene(nextToken.src_str);
299302 next();
300303 }
301304 else if (nextToken.TokenType == TokenType.int_value)
302305 {
303- Console.Write(nextToken.src_str);
306+ codeGene(nextToken.src_str);
304307 next();
305308 }else if (nextToken.TokenType == TokenType.double_value)
306309 {
307- Console.Write(nextToken.src_str);
310+ codeGene(nextToken.src_str);
308311 next();
309312 }else if(nextToken.TokenType == TokenType.Lparen)
310313 {