• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

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

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

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


コミットメタ情報

リビジョン32 (tree)
日時2018-10-19 17:43:19
作者bellyoshi

ログメッセージ

(メッセージはありません)

変更サマリ

差分

--- trunk/crowbar/ver0.1/create.c (revision 31)
+++ trunk/crowbar/ver0.1/create.c (revision 32)
@@ -333,17 +333,22 @@
333333 }
334334
335335 Statement *
336-crb_create_for_statement(Expression *init, Expression *cond,
337- Expression *post, Block *block)
336+crb_create_for_statement(char *identifier,Expression *init,
337+ Expression *to, StatementList *list)
338338 {
339339 Statement *st;
340-
340+ Expression *postinc = crb_alloc_expression(INT_EXPRESSION);
341+ postinc->u.int_value = 1;
342+ Expression *idexpress = crb_create_identifier_expression(identifier);
341343 st = alloc_statement(FOR_STATEMENT);
342- st->u.for_s.init = init;
343- st->u.for_s.condition = cond;
344- st->u.for_s.post = post;
345- st->u.for_s.block = block;
346344
345+ st->u.for_s.init = crb_create_assign_expression(identifier, init);
346+ st->u.for_s.condition = crb_create_binary_expression(NE_EXPRESSION,
347+ idexpress, to);
348+ st->u.for_s.post = crb_create_assign_expression(identifier,
349+ crb_create_binary_expression(ADD_EXPRESSION, idexpress, postinc));
350+ st->u.for_s.block = crb_create_block(list);
351+
347352 return st;
348353 }
349354
@@ -389,4 +394,3 @@
389394 {
390395 return alloc_statement(CONTINUE_STATEMENT);
391396 }
392-
--- trunk/crowbar/ver0.1/crowbar.h (revision 31)
+++ trunk/crowbar/ver0.1/crowbar.h (revision 32)
@@ -311,8 +311,11 @@
311311 Elsif *crb_chain_elsif_list(Elsif *list, Elsif *add);
312312 Elsif *crb_create_elsif(Expression *expr, Block *block);
313313 Statement *crb_create_while_statement(Expression *condition, Block *block);
314-Statement *crb_create_for_statement(Expression *init, Expression *cond,
314+/*Statement *crb_create_for_statement(Expression *init, Expression *cond,
315315 Expression *post, Block *block);
316+*/
317+Statement *crb_create_for_statement(char *identifier,Expression *init,
318+ Expression *to, StatementList *list);
316319 Block *crb_create_block(StatementList *statement_list);
317320 Statement *crb_create_expression_statement(Expression *expression);
318321 Statement *crb_create_return_statement(Expression *expression);
--- trunk/crowbar/ver0.1/crowbar.l (revision 31)
+++ trunk/crowbar/ver0.1/crowbar.l (revision 32)
@@ -19,6 +19,8 @@
1919 %}
2020 %start COMMENT STRING_LITERAL_STATE
2121 %%
22+<INITIAL>"next" return NEXT;
23+<INITIAL>"to" return TO;
2224 <INITIAL>"function" return FUNCTION;
2325 <INITIAL>"if" return IF;
2426 <INITIAL>"else" return ELSE;
--- trunk/crowbar/ver0.1/crowbar.y (revision 31)
+++ trunk/crowbar/ver0.1/crowbar.y (revision 32)
@@ -18,7 +18,8 @@
1818 %token <expression> DOUBLE_LITERAL
1919 %token <expression> STRING_LITERAL
2020 %token <identifier> IDENTIFIER
21-%token FUNCTION IF ELSE ELSIF WHILE FOR RETURN_T BREAK CONTINUE NULL_T
21+%token FUNCTION IF ELSE ELSIF WHILE FOR TO NEXT
22+ RETURN_T BREAK CONTINUE NULL_T
2223 LP RP LC RC SEMICOLON COMMA ASSIGN LOGICAL_AND LOGICAL_OR
2324 EQ NE GT GE LT LE ADD SUB MUL DIV MOD TRUE_T FALSE_T GLOBAL_T
2425 %type <parameter_list> parameter_list
@@ -31,6 +32,7 @@
3132 %type <statement> statement global_statement
3233 if_statement while_statement for_statement
3334 return_statement break_statement continue_statement
35+ hasnum_statement
3436 %type <statement_list> statement_list
3537 %type <block> block
3638 %type <elsif> elsif elsif_list
@@ -42,7 +44,7 @@
4244 ;
4345 definition_or_statement
4446 : function_definition
45- | statement
47+ | hasnum_statement
4648 {
4749 CRB_Interpreter *inter = crb_get_current_interpreter();
4850
@@ -81,11 +83,11 @@
8183 }
8284 ;
8385 statement_list
84- : statement
86+ : hasnum_statement
8587 {
8688 $$ = crb_create_statement_list($1);
8789 }
88- | statement_list statement
90+ | statement_list hasnum_statement
8991 {
9092 $$ = crb_chain_statement_list($1, $2);
9193 }
@@ -207,6 +209,13 @@
207209 $$ = crb_create_null_expression();
208210 }
209211 ;
212+hasnum_statement
213+ : INT_LITERAL statement
214+ {
215+ $$ = $2;
216+ }
217+ | statement
218+ ;
210219 statement
211220 : expression SEMICOLON
212221 {
@@ -274,10 +283,11 @@
274283 }
275284 ;
276285 for_statement
277- : FOR LP expression_opt SEMICOLON expression_opt SEMICOLON
278- expression_opt RP block
286+ : FOR IDENTIFIER ASSIGN expression TO expression
287+ statement_list
288+ NEXT
279289 {
280- $$ = crb_create_for_statement($3, $5, $7, $9);
290+ $$ = crb_create_for_statement($2, $4, $6, $7);
281291 }
282292 ;
283293 expression_opt