• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

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

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

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


コミットメタ情報

リビジョン33 (tree)
日時2018-11-01 14:32:11
作者bellyoshi

ログメッセージ

大文字小文字の区別なし識別子
while文

変更サマリ

差分

--- trunk/crowbar/ver0.1/create.c (revision 32)
+++ trunk/crowbar/ver0.1/create.c (revision 33)
@@ -279,18 +279,17 @@
279279 return list;
280280 }
281281
282-Statement *
283-crb_create_if_statement(Expression *condition,
284- Block *then_block, Elsif *elsif_list,
285- Block *else_block)
282+Statement *crb_create_if_statement(Expression *condition,
283+ StatementList *then_list, Elsif *elsif_list,
284+ StatementList *else_list)
286285 {
287286 Statement *st;
288287
289288 st = alloc_statement(IF_STATEMENT);
290289 st->u.if_s.condition = condition;
291- st->u.if_s.then_block = then_block;
290+ st->u.if_s.then_block = crb_create_block(then_list);
292291 st->u.if_s.elsif_list = elsif_list;
293- st->u.if_s.else_block = else_block;
292+ st->u.if_s.else_block = crb_create_block(else_list);
294293
295294 return st;
296295 }
@@ -308,13 +307,13 @@
308307 }
309308
310309 Elsif *
311-crb_create_elsif(Expression *expr, Block *block)
310+crb_create_elsif(Expression *expr, StatementList *list)
312311 {
313312 Elsif *ei;
314313
315314 ei = crb_malloc(sizeof(Elsif));
316315 ei->condition = expr;
317- ei->block = block;
316+ ei->block = crb_create_block(list);
318317 ei->next = NULL;
319318
320319 return ei;
@@ -321,13 +320,13 @@
321320 }
322321
323322 Statement *
324-crb_create_while_statement(Expression *condition, Block *block)
323+crb_create_while_statement(Expression *condition, StatementList *list)
325324 {
326325 Statement *st;
327326
328327 st = alloc_statement(WHILE_STATEMENT);
329328 st->u.while_s.condition = condition;
330- st->u.while_s.block = block;
329+ st->u.while_s.block = crb_create_block(list);
331330
332331 return st;
333332 }
--- trunk/crowbar/ver0.1/crowbar.h (revision 32)
+++ trunk/crowbar/ver0.1/crowbar.h (revision 33)
@@ -305,15 +305,13 @@
305305 Statement *crb_create_global_statement(IdentifierList *identifier_list);
306306 IdentifierList *crb_create_global_identifier(char *identifier);
307307 IdentifierList *crb_chain_identifier(IdentifierList *list, char *identifier);
308+
308309 Statement *crb_create_if_statement(Expression *condition,
309- Block *then_block, Elsif *elsif_list,
310- Block *else_block);
310+ StatementList *then_list, Elsif *elsif_list,
311+ StatementList *else_list);
311312 Elsif *crb_chain_elsif_list(Elsif *list, Elsif *add);
312-Elsif *crb_create_elsif(Expression *expr, Block *block);
313-Statement *crb_create_while_statement(Expression *condition, Block *block);
314-/*Statement *crb_create_for_statement(Expression *init, Expression *cond,
315- Expression *post, Block *block);
316-*/
313+Elsif *crb_create_elsif(Expression *expr, StatementList *list);
314+Statement *crb_create_while_statement(Expression *condition, StatementList *list);
317315 Statement *crb_create_for_statement(char *identifier,Expression *init,
318316 Expression *to, StatementList *list);
319317 Block *crb_create_block(StatementList *statement_list);
--- trunk/crowbar/ver0.1/crowbar.l (revision 32)
+++ trunk/crowbar/ver0.1/crowbar.l (revision 33)
@@ -18,18 +18,48 @@
1818 }
1919 %}
2020 %start COMMENT STRING_LITERAL_STATE
21+A [aA]
22+B [bB]
23+C [cC]
24+D [dD]
25+E [eE]
26+F [fF]
27+G [gG]
28+H [hH]
29+I [iI]
30+J [jJ]
31+K [kK]
32+L [lL]
33+M [mM]
34+N [nN]
35+O [oO]
36+P [pP]
37+Q [qQ]
38+R [rR]
39+S [sS]
40+T [tT]
41+U [uU]
42+V [vV]
43+W [wW]
44+X [xX]
45+Y [yY]
46+Z [zZ]
2147 %%
22-<INITIAL>"next" return NEXT;
23-<INITIAL>"to" return TO;
24-<INITIAL>"function" return FUNCTION;
25-<INITIAL>"if" return IF;
26-<INITIAL>"else" return ELSE;
27-<INITIAL>"elsif" return ELSIF;
28-<INITIAL>"while" return WHILE;
29-<INITIAL>"for" return FOR;
30-<INITIAL>"return" return RETURN_T;
31-<INITIAL>"break" return BREAK;
32-<INITIAL>"continue" return CONTINUE;
48+<INITIAL>{N}{E}{X}{T} return NEXT;
49+<INITIAL>{T}{O} return TO;
50+<INITIAL>{F}{U}{N}{C}{T}{I}{O}{N} return FUNCTION;
51+<INITIAL>{I}{F} return IF;
52+<INITIAL>{T}{H}{E}{N} return THEN;
53+<INITIAL>{E}{L}{S}{E} return ELSE;
54+<INITIAL>{E}{L}{S}{E}{I}{F} return ELSEIF;
55+<INITIAL>{E}{N}{D} return END;
56+<INITIAL>{S}{T}{E}{P} return STEP;
57+<INITIAL>{W}{E}{N}{D} return WEND;
58+<INITIAL>{W}{H}{I}{L}{E} return WHILE;
59+<INITIAL>{F}{O}{R} return FOR;
60+<INITIAL>{R}{E}{T}{U}{R}{N} return RETURN_T;
61+<INITIAL>{B}{R}{E}{A}{K} return BREAK;
62+<INITIAL>{C}{O}{N}{T}{N}{U}{E} return CONTINUE;
3363 <INITIAL>"null" return NULL_T;
3464 <INITIAL>"true" return TRUE_T;
3565 <INITIAL>"false" return FALSE_T;
@@ -75,7 +105,10 @@
75105 BEGIN STRING_LITERAL_STATE;
76106 }
77107 <INITIAL>[ \t] ;
78-<INITIAL>\n {increment_line_number();}
108+<INITIAL>\n {
109+ increment_line_number();
110+ return CR;
111+}
79112 <INITIAL># BEGIN COMMENT;
80113 <INITIAL>. {
81114 char buf[LINE_BUF_SIZE];
--- trunk/crowbar/ver0.1/crowbar.y (revision 32)
+++ trunk/crowbar/ver0.1/crowbar.y (revision 33)
@@ -18,10 +18,13 @@
1818 %token <expression> DOUBLE_LITERAL
1919 %token <expression> STRING_LITERAL
2020 %token <identifier> IDENTIFIER
21-%token FUNCTION IF ELSE ELSIF WHILE FOR TO NEXT
21+%token FUNCTION
22+ IF THEN ELSE ELSEIF END
23+ WHILE WEND FOR TO NEXT STEP
2224 RETURN_T BREAK CONTINUE NULL_T
2325 LP RP LC RC SEMICOLON COMMA ASSIGN LOGICAL_AND LOGICAL_OR
2426 EQ NE GT GE LT LE ADD SUB MUL DIV MOD TRUE_T FALSE_T GLOBAL_T
27+ CR
2528 %type <parameter_list> parameter_list
2629 %type <argument_list> argument_list
2730 %type <expression> expression expression_opt
@@ -217,7 +220,7 @@
217220 | statement
218221 ;
219222 statement
220- : expression SEMICOLON
223+ : expression statement_terminator
221224 {
222225 $$ = crb_create_expression_statement($1);
223226 }
@@ -230,11 +233,14 @@
230233 | continue_statement
231234 ;
232235 global_statement
233- : GLOBAL_T identifier_list SEMICOLON
236+ : GLOBAL_T identifier_list statement_terminator
234237 {
235238 $$ = crb_create_global_statement($2);
236239 }
237240 ;
241+statement_terminator
242+ : CR
243+ ;
238244 identifier_list
239245 : IDENTIFIER
240246 {
@@ -246,21 +252,35 @@
246252 }
247253 ;
248254 if_statement
249- : IF LP expression RP block
255+ : IF expression THEN statement_terminator
256+ statement_list
257+ END IF statement_terminator
250258 {
251- $$ = crb_create_if_statement($3, $5, NULL, NULL);
259+ $$ = crb_create_if_statement($2, $5, NULL, NULL);
252260 }
253- | IF LP expression RP block ELSE block
261+ | IF expression THEN statement_terminator
262+ statement_list
263+ ELSE statement_terminator
264+ statement_list
265+ END IF statement_terminator
254266 {
255- $$ = crb_create_if_statement($3, $5, NULL, $7);
267+ $$ = crb_create_if_statement($2, $5, NULL, $8);
256268 }
257- | IF LP expression RP block elsif_list
269+ | IF expression THEN statement_terminator
270+ statement_list
271+ elsif_list
272+ END IF statement_terminator
258273 {
259- $$ = crb_create_if_statement($3, $5, $6, NULL);
274+ $$ = crb_create_if_statement($2, $5, $6, NULL);
260275 }
261- | IF LP expression RP block elsif_list ELSE block
276+ | IF expression THEN statement_terminator
277+ statement_list
278+ elsif_list
279+ ELSE statement_terminator
280+ statement_list
281+ END IF statement_terminator
262282 {
263- $$ = crb_create_if_statement($3, $5, $6, $8);
283+ $$ = crb_create_if_statement($2, $5, $6, $9);
264284 }
265285 ;
266286 elsif_list
@@ -271,23 +291,26 @@
271291 }
272292 ;
273293 elsif
274- : ELSIF LP expression RP block
294+ : ELSEIF expression THEN statement_terminator
295+ statement_list
275296 {
276- $$ = crb_create_elsif($3, $5);
297+ $$ = crb_create_elsif($2, $5);
277298 }
278299 ;
279300 while_statement
280- : WHILE LP expression RP block
301+ : WHILE expression statement_terminator
302+ statement_list
303+ WEND statement_terminator
281304 {
282- $$ = crb_create_while_statement($3, $5);
305+ $$ = crb_create_while_statement($2, $4);
283306 }
284307 ;
285308 for_statement
286- : FOR IDENTIFIER ASSIGN expression TO expression
309+ : FOR IDENTIFIER ASSIGN expression TO expression statement_terminator
287310 statement_list
288- NEXT
311+ NEXT statement_terminator
289312 {
290- $$ = crb_create_for_statement($2, $4, $6, $7);
313+ $$ = crb_create_for_statement($2, $4, $6, $8);
291314 }
292315 ;
293316 expression_opt
@@ -298,19 +321,19 @@
298321 | expression
299322 ;
300323 return_statement
301- : RETURN_T expression_opt SEMICOLON
324+ : RETURN_T expression_opt statement_terminator
302325 {
303326 $$ = crb_create_return_statement($2);
304327 }
305328 ;
306329 break_statement
307- : BREAK SEMICOLON
330+ : BREAK statement_terminator
308331 {
309332 $$ = crb_create_break_statement();
310333 }
311334 ;
312335 continue_statement
313- : CONTINUE SEMICOLON
336+ : CONTINUE statement_terminator
314337 {
315338 $$ = crb_create_continue_statement();
316339 }