- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/core/parse.y
r270 r331 23 23 #include <stdlib.h> 24 24 #include <string.h> 25 #include "mruby.h" 26 #include "mruby/compile.h" 27 #include "mruby/proc.h" 28 #include "mruby/error.h" 25 #include <mruby.h> 26 #include <mruby/compile.h> 27 #include <mruby/proc.h> 28 #include <mruby/error.h> 29 #include <mruby/throw.h> 29 30 #include "node.h" 30 #include "mruby/throw.h"31 31 32 32 #define YYLEX_PARAM p … … 42 42 static void yywarning(parser_state *p, const char *s); 43 43 static void backref_error(parser_state *p, node *n); 44 static void void_expr_error(parser_state *p, node *n); 44 45 static void tokadd(parser_state *p, int32_t c); 45 46 … … 73 74 #define sym(x) ((mrb_sym)(intptr_t)(x)) 74 75 #define nsym(x) ((node*)(intptr_t)(x)) 76 #define nint(x) ((node*)(intptr_t)(x)) 77 #define intn(x) ((int)(intptr_t)(x)) 75 78 76 79 static inline mrb_sym … … 309 312 } 310 313 314 static node* 315 new_mod_rescue(parser_state *p, node *body, node *resq) 316 { 317 return new_rescue(p, body, list1(list3(0, 0, resq)), 0); 318 } 319 311 320 /* (:ensure body ensure) */ 312 321 static node* … … 348 357 new_if(parser_state *p, node *a, node *b, node *c) 349 358 { 359 void_expr_error(p, a); 350 360 return list4((node*)NODE_IF, a, b, c); 351 361 } … … 355 365 new_unless(parser_state *p, node *a, node *b, node *c) 356 366 { 367 void_expr_error(p, a); 357 368 return list4((node*)NODE_IF, a, c, b); 358 369 } … … 362 373 new_while(parser_state *p, node *a, node *b) 363 374 { 375 void_expr_error(p, a); 364 376 return cons((node*)NODE_WHILE, cons(a, b)); 365 377 } … … 369 381 new_until(parser_state *p, node *a, node *b) 370 382 { 383 void_expr_error(p, a); 371 384 return cons((node*)NODE_UNTIL, cons(a, b)); 372 385 } … … 376 389 new_for(parser_state *p, node *v, node *o, node *b) 377 390 { 391 void_expr_error(p, o); 378 392 return list4((node*)NODE_FOR, v, o, b); 379 393 } … … 386 400 node *n2 = n; 387 401 402 void_expr_error(p, a); 388 403 while (n2->cdr) { 389 404 n2 = n2->cdr; … … 409 424 /* (:call a b c) */ 410 425 static node* 411 new_call(parser_state *p, node *a, mrb_sym b, node *c) 412 { 413 node *n = list4((node*)NODE_CALL, a, nsym(b), c); 426 new_call(parser_state *p, node *a, mrb_sym b, node *c, int pass) 427 { 428 node *n = list4(nint(pass?NODE_CALL:NODE_SCALL), a, nsym(b), c); 429 void_expr_error(p, a); 414 430 NODE_LINENO(n, a); 415 431 return n; … … 507 523 new_colon2(parser_state *p, node *b, mrb_sym c) 508 524 { 525 void_expr_error(p, b); 509 526 return cons((node*)NODE_COLON2, cons(b, nsym(c))); 510 527 } … … 614 631 new_class(parser_state *p, node *c, node *s, node *b) 615 632 { 633 void_expr_error(p, s); 616 634 return list4((node*)NODE_CLASS, c, s, cons(locals_node(p), b)); 617 635 } … … 621 639 new_sclass(parser_state *p, node *o, node *b) 622 640 { 641 void_expr_error(p, o); 623 642 return list3((node*)NODE_SCLASS, o, cons(locals_node(p), b)); 624 643 } … … 642 661 new_sdef(parser_state *p, node *o, mrb_sym m, node *a, node *b) 643 662 { 663 void_expr_error(p, o); 644 664 return list6((node*)NODE_SDEF, o, nsym(m), locals_node(p), a, b); 645 665 } … … 694 714 new_asgn(parser_state *p, node *a, node *b) 695 715 { 716 void_expr_error(p, b); 696 717 return cons((node*)NODE_ASGN, cons(a, b)); 697 718 } … … 701 722 new_masgn(parser_state *p, node *a, node *b) 702 723 { 724 void_expr_error(p, b); 703 725 return cons((node*)NODE_MASGN, cons(a, b)); 704 726 } … … 708 730 new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b) 709 731 { 732 void_expr_error(p, b); 710 733 return list4((node*)NODE_OP_ASGN, a, nsym(op), b); 711 734 } … … 715 738 new_int(parser_state *p, const char *s, int base) 716 739 { 717 return list3((node*)NODE_INT, (node*)strdup(s), (node*)(intptr_t)base);740 return list3((node*)NODE_INT, (node*)strdup(s), nint(base)); 718 741 } 719 742 … … 729 752 new_str(parser_state *p, const char *s, int len) 730 753 { 731 return cons((node*)NODE_STR, cons((node*)strndup(s, len), (node*)(intptr_t)len));754 return cons((node*)NODE_STR, cons((node*)strndup(s, len), nint(len))); 732 755 } 733 756 … … 743 766 new_xstr(parser_state *p, const char *s, int len) 744 767 { 745 return cons((node*)NODE_XSTR, cons((node*)strndup(s, len), (node*)(intptr_t)len));768 return cons((node*)NODE_XSTR, cons((node*)strndup(s, len), nint(len))); 746 769 } 747 770 … … 760 783 } 761 784 762 /* (: str . (a . a)) */785 /* (:regx . (s . (opt . enc))) */ 763 786 static node* 764 787 new_regx(parser_state *p, const char *p1, const char* p2, const char* p3) … … 767 790 } 768 791 769 /* (:dregx . a) */792 /* (:dregx . (a . b)) */ 770 793 static node* 771 794 new_dregx(parser_state *p, node *a, node *b) … … 778 801 new_back_ref(parser_state *p, int n) 779 802 { 780 return cons((node*)NODE_BACK_REF, (node*)(intptr_t)n);803 return cons((node*)NODE_BACK_REF, nint(n)); 781 804 } 782 805 … … 785 808 new_nth_ref(parser_state *p, int n) 786 809 { 787 return cons((node*)NODE_NTH_REF, (node*)(intptr_t)n);810 return cons((node*)NODE_NTH_REF, nint(n)); 788 811 } 789 812 … … 827 850 call_uni_op(parser_state *p, node *recv, const char *m) 828 851 { 829 return new_call(p, recv, intern_cstr(m), 0); 852 void_expr_error(p, recv); 853 return new_call(p, recv, intern_cstr(m), 0, 1); 830 854 } 831 855 … … 834 858 call_bin_op(parser_state *p, node *recv, const char *m, node *arg1) 835 859 { 836 return new_call(p, recv, intern_cstr(m), list1(list1(arg1)) );860 return new_call(p, recv, intern_cstr(m), list1(list1(arg1)), 1); 837 861 } 838 862 … … 853 877 node *n; 854 878 855 if (a->car == (node*)NODE_SUPER || 856 a->car == (node*)NODE_ZSUPER) { 879 switch ((enum node_type)intn(a->car)) { 880 case NODE_SUPER: 881 case NODE_ZSUPER: 857 882 if (!a->cdr) a->cdr = cons(0, b); 858 883 else { 859 884 args_with_block(p, a->cdr, b); 860 885 } 861 } 862 else { 886 break; 887 case NODE_CALL: 888 case NODE_FCALL: 889 case NODE_SCALL: 863 890 n = a->cdr->cdr->cdr; 864 891 if (!n->car) n->car = cons(0, b); … … 866 893 args_with_block(p, n->car, b); 867 894 } 895 break; 896 default: 897 break; 868 898 } 869 899 } … … 895 925 assignable(parser_state *p, node *lhs) 896 926 { 897 if ( (int)(intptr_t)lhs->car== NODE_LVAR) {927 if (intn(lhs->car) == NODE_LVAR) { 898 928 local_add(p, sym(lhs->cdr)); 899 929 } … … 905 935 node *n; 906 936 907 if ( (int)(intptr_t)lhs->car== NODE_LVAR) {937 if (intn(lhs->car) == NODE_LVAR) { 908 938 if (!local_var_p(p, sym(lhs->cdr))) { 909 939 n = new_fcall(p, sym(lhs->cdr), 0); … … 921 951 new_strterm(parser_state *p, string_type type, int term, int paren) 922 952 { 923 return cons( (node*)(intptr_t)type, cons((node*)0, cons((node*)(intptr_t)paren, (node*)(intptr_t)term)));953 return cons(nint(type), cons((node*)0, cons(nint(paren), nint(term)))); 924 954 } 925 955 … … 1002 1032 else { 1003 1033 /* next heredoc */ 1004 p->lex_strterm->car = (node*)(intptr_t)parsing_heredoc_inf(p)->type;1005 } 1006 } 1007 #define is_strterm_type(p,str_func) ( (int)(intptr_t)((p)->lex_strterm->car) & (str_func))1034 p->lex_strterm->car = nint(parsing_heredoc_inf(p)->type); 1035 } 1036 } 1037 #define is_strterm_type(p,str_func) (intn((p)->lex_strterm->car) & (str_func)) 1008 1038 1009 1039 /* xxx ----------------------------- */ … … 1077 1107 %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL 1078 1108 %token <nd> tINTEGER tFLOAT tCHAR tXSTRING tREGEXP 1079 %token <nd> tSTRING tSTRING_PART tSTRING_MID 1109 %token <nd> tSTRING tSTRING_PART tSTRING_MID tLABEL_END 1080 1110 %token <nd> tNTH_REF tBACK_REF 1081 1111 %token <num> tREGEXP_END … … 1085 1115 %type <nd> top_compstmt top_stmts top_stmt 1086 1116 %type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call 1087 %type <nd> expr_value arg_ valueprimary_value1117 %type <nd> expr_value arg_rhs primary_value 1088 1118 %type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure 1089 1119 %type <nd> args call_args opt_call_args 1090 1120 %type <nd> paren_args opt_paren_args variable 1091 1121 %type <nd> command_args aref_args opt_block_arg block_arg var_ref var_lhs 1092 %type <nd> command_asgn mrhs superclass block_call block_command1122 %type <nd> command_asgn command_rhs mrhs superclass block_call block_command 1093 1123 %type <nd> f_block_optarg f_block_opt 1094 1124 %type <nd> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs … … 1101 1131 %type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_opt_asgn 1102 1132 %type <nd> heredoc words symbols 1133 %type <num> call_op call_op2 /* 0:'&.', 1:'.', 2:'::' */ 1103 1134 1104 1135 %token tUPLUS /* unary+ */ … … 1129 1160 %token tAMPER /* & */ 1130 1161 %token tLAMBDA /* -> */ 1162 %token tANDDOT /* &. */ 1131 1163 %token tSYMBEG tREGEXP_BEG tWORDS_BEG tSYMBOLS_BEG 1132 1164 %token tSTRING_BEG tXSTRING_BEG tSTRING_DVAR tLAMBEG … … 1292 1324 | stmt modifier_rescue stmt 1293 1325 { 1294 $$ = new_ rescue(p, $1, list1(list3(0, 0, $3)), 0);1326 $$ = new_mod_rescue(p, $1, $3); 1295 1327 } 1296 1328 | keyword_END '{' compstmt '}' 1297 1329 { 1298 yyerror(p, "END not sup orted");1330 yyerror(p, "END not supported"); 1299 1331 $$ = new_postexe(p, $3); 1300 1332 } … … 1304 1336 $$ = new_masgn(p, $1, $3); 1305 1337 } 1306 | var_lhs tOP_ASGN command_call 1338 | lhs '=' mrhs 1339 { 1340 $$ = new_asgn(p, $1, new_array(p, $3)); 1341 } 1342 | mlhs '=' arg 1343 { 1344 $$ = new_masgn(p, $1, $3); 1345 } 1346 | mlhs '=' mrhs 1347 { 1348 $$ = new_masgn(p, $1, new_array(p, $3)); 1349 } 1350 | expr 1351 ; 1352 1353 command_asgn : lhs '=' command_rhs 1354 { 1355 $$ = new_asgn(p, $1, $3); 1356 } 1357 | var_lhs tOP_ASGN command_rhs 1307 1358 { 1308 1359 $$ = new_op_asgn(p, $1, $2, $3); 1309 1360 } 1310 | primary_value '[' opt_call_args rbracket tOP_ASGN command_ call1311 { 1312 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3 ), $5, $6);1313 } 1314 | primary_value '.' tIDENTIFIER tOP_ASGN command_call1315 { 1316 $$ = new_op_asgn(p, new_call(p, $1, $3, 0 ), $4, $5);1317 } 1318 | primary_value '.' tCONSTANT tOP_ASGN command_call1319 { 1320 $$ = new_op_asgn(p, new_call(p, $1, $3, 0 ), $4, $5);1361 | primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs 1362 { 1363 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); 1364 } 1365 | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs 1366 { 1367 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1368 } 1369 | primary_value call_op tCONSTANT tOP_ASGN command_rhs 1370 { 1371 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1321 1372 } 1322 1373 | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call … … 1325 1376 $$ = 0; 1326 1377 } 1327 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_ call1328 { 1329 $$ = new_op_asgn(p, new_call(p, $1, $3, 0 ), $4, $5);1330 } 1331 | backref tOP_ASGN command_ call1378 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs 1379 { 1380 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); 1381 } 1382 | backref tOP_ASGN command_rhs 1332 1383 { 1333 1384 backref_error(p, $1); 1334 1385 $$ = new_begin(p, 0); 1335 1386 } 1336 | lhs '=' mrhs 1337 { 1338 $$ = new_asgn(p, $1, new_array(p, $3)); 1339 } 1340 | mlhs '=' arg_value 1341 { 1342 $$ = new_masgn(p, $1, $3); 1343 } 1344 | mlhs '=' mrhs 1345 { 1346 $$ = new_masgn(p, $1, new_array(p, $3)); 1347 } 1348 | expr 1349 ; 1350 1351 command_asgn : lhs '=' command_call 1352 { 1353 $$ = new_asgn(p, $1, $3); 1354 } 1355 | lhs '=' command_asgn 1356 { 1357 $$ = new_asgn(p, $1, $3); 1358 } 1387 ; 1388 1389 command_rhs : command_call %prec tOP_ASGN 1390 | command_call modifier_rescue stmt 1391 { 1392 $$ = new_mod_rescue(p, $1, $3); 1393 } 1394 | command_asgn 1359 1395 ; 1360 1396 … … 1383 1419 { 1384 1420 if (!$1) $$ = new_nil(p); 1385 else $$ = $1; 1421 else { 1422 $$ = $1; 1423 } 1386 1424 } 1387 1425 ; … … 1392 1430 1393 1431 block_command : block_call 1394 | block_call dot_or_colon operation2 command_args 1432 | block_call call_op2 operation2 command_args 1433 { 1434 $$ = new_call(p, $1, $3, $4, $2); 1435 } 1395 1436 ; 1396 1437 … … 1417 1458 $$ = new_fcall(p, $1, $2); 1418 1459 } 1419 | primary_value '.'operation2 command_args %prec tLOWEST1420 { 1421 $$ = new_call(p, $1, $3, $4 );1422 } 1423 | primary_value '.'operation2 command_args cmd_brace_block1460 | primary_value call_op operation2 command_args %prec tLOWEST 1461 { 1462 $$ = new_call(p, $1, $3, $4, $2); 1463 } 1464 | primary_value call_op operation2 command_args cmd_brace_block 1424 1465 { 1425 1466 args_with_block(p, $4, $5); 1426 $$ = new_call(p, $1, $3, $4 );1467 $$ = new_call(p, $1, $3, $4, $2); 1427 1468 } 1428 1469 | primary_value tCOLON2 operation2 command_args %prec tLOWEST 1429 1470 { 1430 $$ = new_call(p, $1, $3, $4 );1471 $$ = new_call(p, $1, $3, $4, tCOLON2); 1431 1472 } 1432 1473 | primary_value tCOLON2 operation2 command_args cmd_brace_block 1433 1474 { 1434 1475 args_with_block(p, $4, $5); 1435 $$ = new_call(p, $1, $3, $4 );1476 $$ = new_call(p, $1, $3, $4, tCOLON2); 1436 1477 } 1437 1478 | keyword_super command_args … … 1549 1590 | primary_value '[' opt_call_args rbracket 1550 1591 { 1551 $$ = new_call(p, $1, intern("[]",2), $3 );1552 } 1553 | primary_value '.'tIDENTIFIER1554 { 1555 $$ = new_call(p, $1, $3, 0 );1592 $$ = new_call(p, $1, intern("[]",2), $3, '.'); 1593 } 1594 | primary_value call_op tIDENTIFIER 1595 { 1596 $$ = new_call(p, $1, $3, 0, $2); 1556 1597 } 1557 1598 | primary_value tCOLON2 tIDENTIFIER 1558 1599 { 1559 $$ = new_call(p, $1, $3, 0 );1560 } 1561 | primary_value '.'tCONSTANT1562 { 1563 $$ = new_call(p, $1, $3, 0 );1600 $$ = new_call(p, $1, $3, 0, tCOLON2); 1601 } 1602 | primary_value call_op tCONSTANT 1603 { 1604 $$ = new_call(p, $1, $3, 0, $2); 1564 1605 } 1565 1606 | primary_value tCOLON2 tCONSTANT … … 1588 1629 | primary_value '[' opt_call_args rbracket 1589 1630 { 1590 $$ = new_call(p, $1, intern("[]",2), $3 );1591 } 1592 | primary_value '.'tIDENTIFIER1593 { 1594 $$ = new_call(p, $1, $3, 0 );1631 $$ = new_call(p, $1, intern("[]",2), $3, '.'); 1632 } 1633 | primary_value call_op tIDENTIFIER 1634 { 1635 $$ = new_call(p, $1, $3, 0, $2); 1595 1636 } 1596 1637 | primary_value tCOLON2 tIDENTIFIER 1597 1638 { 1598 $$ = new_call(p, $1, $3, 0 );1599 } 1600 | primary_value '.'tCONSTANT1601 { 1602 $$ = new_call(p, $1, $3, 0 );1639 $$ = new_call(p, $1, $3, 0, tCOLON2); 1640 } 1641 | primary_value call_op tCONSTANT 1642 { 1643 $$ = new_call(p, $1, $3, 0, $2); 1603 1644 } 1604 1645 | primary_value tCOLON2 tCONSTANT … … 1638 1679 | primary_value tCOLON2 cname 1639 1680 { 1681 void_expr_error(p, $1); 1640 1682 $$ = cons($1, nsym($3)); 1641 1683 } … … 1716 1758 ; 1717 1759 1718 arg : lhs '=' arg 1760 arg : lhs '=' arg_rhs 1719 1761 { 1720 1762 $$ = new_asgn(p, $1, $3); 1721 1763 } 1722 | lhs '=' arg modifier_rescue arg 1723 { 1724 $$ = new_asgn(p, $1, new_rescue(p, $3, list1(list3(0, 0, $5)), 0)); 1725 } 1726 | var_lhs tOP_ASGN arg 1764 | var_lhs tOP_ASGN arg_rhs 1727 1765 { 1728 1766 $$ = new_op_asgn(p, $1, $2, $3); 1729 1767 } 1730 | var_lhs tOP_ASGN arg modifier_rescue arg 1731 { 1732 $$ = new_op_asgn(p, $1, $2, new_rescue(p, $3, list1(list3(0, 0, $5)), 0)); 1733 } 1734 | primary_value '[' opt_call_args rbracket tOP_ASGN arg 1735 { 1736 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3), $5, $6); 1737 } 1738 | primary_value '.' tIDENTIFIER tOP_ASGN arg 1739 { 1740 $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5); 1741 } 1742 | primary_value '.' tCONSTANT tOP_ASGN arg 1743 { 1744 $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5); 1745 } 1746 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg 1747 { 1748 $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5); 1749 } 1750 | primary_value tCOLON2 tCONSTANT tOP_ASGN arg 1768 | primary_value '[' opt_call_args rbracket tOP_ASGN arg_rhs 1769 { 1770 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); 1771 } 1772 | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs 1773 { 1774 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1775 } 1776 | primary_value call_op tCONSTANT tOP_ASGN arg_rhs 1777 { 1778 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1779 } 1780 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs 1781 { 1782 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); 1783 } 1784 | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs 1751 1785 { 1752 1786 yyerror(p, "constant re-assignment"); 1753 1787 $$ = new_begin(p, 0); 1754 1788 } 1755 | tCOLON3 tCONSTANT tOP_ASGN arg 1789 | tCOLON3 tCONSTANT tOP_ASGN arg_rhs 1756 1790 { 1757 1791 yyerror(p, "constant re-assignment"); 1758 1792 $$ = new_begin(p, 0); 1759 1793 } 1760 | backref tOP_ASGN arg 1794 | backref tOP_ASGN arg_rhs 1761 1795 { 1762 1796 backref_error(p, $1); … … 1897 1931 ; 1898 1932 1899 arg_value : arg1900 {1901 $$ = $1;1902 if (!$$) $$ = new_nil(p);1903 }1904 ;1905 1906 1933 aref_args : none 1907 1934 | args trailer … … 1910 1937 NODE_LINENO($$, $1); 1911 1938 } 1912 | args ','assocs trailer1939 | args comma assocs trailer 1913 1940 { 1914 1941 $$ = push($1, new_hash(p, $3)); … … 1918 1945 $$ = cons(new_hash(p, $1), 0); 1919 1946 NODE_LINENO($$, $1); 1947 } 1948 ; 1949 1950 arg_rhs : arg %prec tOP_ASGN 1951 { 1952 $$ = $1; 1953 } 1954 | arg modifier_rescue arg 1955 { 1956 void_expr_error(p, $1); 1957 void_expr_error(p, $3); 1958 $$ = new_mod_rescue(p, $1, $3); 1920 1959 } 1921 1960 ; … … 1938 1977 NODE_LINENO($$, $1); 1939 1978 } 1940 | args ','assocs ','1979 | args comma assocs ',' 1941 1980 { 1942 1981 $$ = cons(push($1, new_hash(p, $3)), 0); … … 1952 1991 call_args : command 1953 1992 { 1993 void_expr_error(p, $1); 1954 1994 $$ = cons(list1($1), 0); 1955 1995 NODE_LINENO($$, $1); … … 1965 2005 NODE_LINENO($$, $1); 1966 2006 } 1967 | args ','assocs opt_block_arg2007 | args comma assocs opt_block_arg 1968 2008 { 1969 2009 $$ = cons(push($1, new_hash(p, $3)), $4); … … 1988 2028 ; 1989 2029 1990 block_arg : tAMPER arg _value2030 block_arg : tAMPER arg 1991 2031 { 1992 2032 $$ = new_block_arg(p, $2); … … 1994 2034 ; 1995 2035 1996 opt_block_arg : ','block_arg2036 opt_block_arg : comma block_arg 1997 2037 { 1998 2038 $$ = $2; … … 2004 2044 ; 2005 2045 2006 args : arg_value 2007 { 2046 comma : ',' 2047 | ',' heredoc_bodies 2048 ; 2049 2050 args : arg 2051 { 2052 void_expr_error(p, $1); 2008 2053 $$ = cons($1, 0); 2009 2054 NODE_LINENO($$, $1); 2010 2055 } 2011 | tSTAR arg_value 2012 { 2056 | tSTAR arg 2057 { 2058 void_expr_error(p, $2); 2013 2059 $$ = cons(new_splat(p, $2), 0); 2014 2060 NODE_LINENO($$, $2); 2015 2061 } 2016 | args ',' arg_value 2017 { 2062 | args comma arg 2063 { 2064 void_expr_error(p, $3); 2018 2065 $$ = push($1, $3); 2019 2066 } 2020 | args ',' tSTAR arg_value 2021 { 2067 | args comma tSTAR arg 2068 { 2069 void_expr_error(p, $4); 2022 2070 $$ = push($1, new_splat(p, $4)); 2023 2071 } 2024 | args ',' heredoc_bodies arg_value 2025 { 2026 $$ = push($1, $4); 2027 } 2028 | args ',' heredoc_bodies tSTAR arg_value 2029 { 2030 $$ = push($1, new_splat(p, $5)); 2031 } 2032 ; 2033 2034 mrhs : args ',' arg_value 2035 { 2072 ; 2073 2074 mrhs : args comma arg 2075 { 2076 void_expr_error(p, $3); 2036 2077 $$ = push($1, $3); 2037 2078 } 2038 | args ',' tSTAR arg_value 2039 { 2079 | args comma tSTAR arg 2080 { 2081 void_expr_error(p, $4); 2040 2082 $$ = push($1, new_splat(p, $4)); 2041 2083 } 2042 | tSTAR arg_value 2043 { 2084 | tSTAR arg 2085 { 2086 void_expr_error(p, $2); 2044 2087 $$ = list1(new_splat(p, $2)); 2045 2088 } … … 2073 2116 p->cmdarg_stack = 0; 2074 2117 } 2075 expr{p->lstate = EXPR_ENDARG;} rparen2118 stmt {p->lstate = EXPR_ENDARG;} rparen 2076 2119 { 2077 2120 p->cmdarg_stack = $<stack>2; … … 2080 2123 | tLPAREN_ARG {p->lstate = EXPR_ENDARG;} rparen 2081 2124 { 2082 $$ = 0;2125 $$ = new_nil(p); 2083 2126 } 2084 2127 | tLPAREN compstmt ')' … … 2108 2151 $$ = new_return(p, 0); 2109 2152 } 2110 | keyword_yield '(' call_args rparen 2111 { 2112 $$ = new_yield(p, $3); 2113 } 2114 | keyword_yield '(' rparen 2115 { 2116 $$ = new_yield(p, 0); 2117 } 2118 | keyword_yield 2119 { 2120 $$ = new_yield(p, 0); 2153 | keyword_yield opt_paren_args 2154 { 2155 $$ = new_yield(p, $2); 2121 2156 } 2122 2157 | keyword_not '(' expr rparen … … 2229 2264 term 2230 2265 { 2231 $<nd>$ = cons(local_switch(p), (node*)(intptr_t)p->in_single);2266 $<nd>$ = cons(local_switch(p), nint(p->in_single)); 2232 2267 p->in_single = 0; 2233 2268 } … … 2239 2274 local_resume(p, $<nd>6->car); 2240 2275 p->in_def = $<num>4; 2241 p->in_single = (int)(intptr_t)$<nd>6->cdr;2276 p->in_single = intn($<nd>6->cdr); 2242 2277 } 2243 2278 | keyword_module … … 2433 2468 | f_arg ',' 2434 2469 { 2435 $$ = new_args(p, $1, 0, 1, 0, 0);2470 $$ = new_args(p, $1, 0, 0, 0, 0); 2436 2471 } 2437 2472 | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg … … 2561 2596 $$ = $1; 2562 2597 } 2563 | block_call dot_or_colonoperation2 opt_paren_args2564 { 2565 $$ = new_call(p, $1, $3, $4 );2566 } 2567 | block_call dot_or_colonoperation2 opt_paren_args brace_block2568 { 2569 $$ = new_call(p, $1, $3, $4 );2598 | block_call call_op2 operation2 opt_paren_args 2599 { 2600 $$ = new_call(p, $1, $3, $4, $2); 2601 } 2602 | block_call call_op2 operation2 opt_paren_args brace_block 2603 { 2604 $$ = new_call(p, $1, $3, $4, $2); 2570 2605 call_with_block(p, $$, $5); 2571 2606 } 2572 | block_call dot_or_colonoperation2 command_args do_block2573 { 2574 $$ = new_call(p, $1, $3, $4 );2607 | block_call call_op2 operation2 command_args do_block 2608 { 2609 $$ = new_call(p, $1, $3, $4, $2); 2575 2610 call_with_block(p, $$, $5); 2576 2611 } … … 2581 2616 $$ = new_fcall(p, $1, $2); 2582 2617 } 2583 | primary_value '.'operation2 opt_paren_args2584 { 2585 $$ = new_call(p, $1, $3, $4 );2618 | primary_value call_op operation2 opt_paren_args 2619 { 2620 $$ = new_call(p, $1, $3, $4, $2); 2586 2621 } 2587 2622 | primary_value tCOLON2 operation2 paren_args 2588 2623 { 2589 $$ = new_call(p, $1, $3, $4 );2624 $$ = new_call(p, $1, $3, $4, tCOLON2); 2590 2625 } 2591 2626 | primary_value tCOLON2 operation3 2592 2627 { 2593 $$ = new_call(p, $1, $3, 0 );2594 } 2595 | primary_value '.'paren_args2596 { 2597 $$ = new_call(p, $1, intern("call",4), $3 );2628 $$ = new_call(p, $1, $3, 0, tCOLON2); 2629 } 2630 | primary_value call_op paren_args 2631 { 2632 $$ = new_call(p, $1, intern("call",4), $3, $2); 2598 2633 } 2599 2634 | primary_value tCOLON2 paren_args 2600 2635 { 2601 $$ = new_call(p, $1, intern("call",4), $3 );2636 $$ = new_call(p, $1, intern("call",4), $3, tCOLON2); 2602 2637 } 2603 2638 | keyword_super paren_args … … 2611 2646 | primary_value '[' opt_call_args rbracket 2612 2647 { 2613 $$ = new_call(p, $1, intern("[]",2), $3 );2648 $$ = new_call(p, $1, intern("[]",2), $3, '.'); 2614 2649 } 2615 2650 ; … … 2671 2706 ; 2672 2707 2673 exc_list : arg _value2708 exc_list : arg 2674 2709 { 2675 2710 $$ = list1($1); … … 2766 2801 ; 2767 2802 2768 opt_heredoc_bodies : /* none */2769 | heredoc_bodies2770 ;2771 2772 2803 heredoc_bodies : heredoc_body 2773 2804 | heredoc_bodies heredoc_body … … 2825 2856 $$ = new_sym(p, $1); 2826 2857 } 2827 | tSYMBEG tSTRING_BEG string_ interp tSTRING2858 | tSYMBEG tSTRING_BEG string_rep tSTRING 2828 2859 { 2829 2860 p->lstate = EXPR_END; … … 2925 2956 | keyword__FILE__ 2926 2957 { 2927 if (!p->filename) { 2928 p->filename = "(null)"; 2958 const char *fn = p->filename; 2959 if (!fn) { 2960 fn = "(null)"; 2929 2961 } 2930 $$ = new_str(p, p->filename, strlen(p->filename));2962 $$ = new_str(p, fn, strlen(fn)); 2931 2963 } 2932 2964 | keyword__LINE__ … … 2955 2987 { 2956 2988 $$ = $3; 2957 } /* 2989 } /* 2958 2990 | error term 2959 2991 { … … 3098 3130 ; 3099 3131 3100 f_opt : f_opt_asgn arg_value 3101 { 3132 f_opt : f_opt_asgn arg 3133 { 3134 void_expr_error(p, $2); 3102 3135 $$ = cons(nsym($1), $2); 3103 3136 } … … 3106 3139 f_block_opt : f_opt_asgn primary_value 3107 3140 { 3141 void_expr_error(p, $2); 3108 3142 $$ = cons(nsym($1), $2); 3109 3143 } … … 3179 3213 } 3180 3214 else { 3181 switch ((enum node_type) (int)(intptr_t)$3->car) {3215 switch ((enum node_type)intn($3->car)) { 3182 3216 case NODE_STR: 3183 3217 case NODE_DSTR: … … 3216 3250 ; 3217 3251 3218 assoc : arg_value tASSOC arg_value 3219 { 3252 assoc : arg tASSOC arg 3253 { 3254 void_expr_error(p, $1); 3255 void_expr_error(p, $3); 3220 3256 $$ = cons($1, $3); 3221 3257 } 3222 | tLABEL arg_value 3223 { 3258 | tLABEL arg 3259 { 3260 void_expr_error(p, $2); 3224 3261 $$ = cons(new_sym(p, $1), $2); 3262 } 3263 | tLABEL_END arg 3264 { 3265 void_expr_error(p, $2); 3266 $$ = cons(new_sym(p, new_strsym(p, $1)), $2); 3267 } 3268 | tSTRING_BEG tLABEL_END arg 3269 { 3270 void_expr_error(p, $3); 3271 $$ = cons(new_sym(p, new_strsym(p, $2)), $3); 3272 } 3273 | tSTRING_BEG string_rep tLABEL_END arg 3274 { 3275 void_expr_error(p, $4); 3276 $$ = cons(new_dsym(p, push($2, $3)), $4); 3225 3277 } 3226 3278 ; … … 3246 3298 ; 3247 3299 3300 call_op : '.' 3301 { 3302 $$ = '.'; 3303 } 3304 | tANDDOT 3305 { 3306 $$ = 0; 3307 } 3308 ; 3309 3310 call_op2 : call_op 3311 | tCOLON2 3312 { 3313 $$ = tCOLON2; 3314 } 3315 ; 3316 3248 3317 opt_terms : /* none */ 3249 3318 | terms … … 3262 3331 trailer : /* none */ 3263 3332 | nl 3264 | ','3333 | comma 3265 3334 ; 3266 3335 3267 3336 term : ';' {yyerrok;} 3268 3337 | nl 3338 | heredoc_body 3269 3339 ; 3270 3340 … … 3274 3344 p->column = 0; 3275 3345 } 3276 opt_heredoc_bodies3346 ; 3277 3347 3278 3348 terms : term 3279 | terms ';' {yyerrok;}3349 | terms term 3280 3350 ; 3281 3351 … … 3286 3356 ; 3287 3357 %% 3288 #define yylval (*((YYSTYPE*)(p->ylval)))3358 #define pylval (*((YYSTYPE*)(p->ylval))) 3289 3359 3290 3360 static void … … 3374 3444 3375 3445 if (c == NODE_NTH_REF) { 3376 yyerror_i(p, "can't set variable $% d", (int)(intptr_t)n->cdr);3446 yyerror_i(p, "can't set variable $%" MRB_PRId, (mrb_int)(intptr_t)n->cdr); 3377 3447 } 3378 3448 else if (c == NODE_BACK_REF) { … … 3381 3451 else { 3382 3452 mrb_bug(p->mrb, "Internal error in backref_error() : n=>car == %S", mrb_fixnum_value(c)); 3453 } 3454 } 3455 3456 static void 3457 void_expr_error(parser_state *p, node *n) 3458 { 3459 int c; 3460 3461 if (n == NULL) return; 3462 c = (int)(intptr_t)n->car; 3463 switch (c) { 3464 case NODE_BREAK: 3465 case NODE_RETURN: 3466 case NODE_NEXT: 3467 case NODE_REDO: 3468 case NODE_RETRY: 3469 yyerror(p, "void value expression"); 3470 break; 3471 case NODE_AND: 3472 case NODE_OR: 3473 void_expr_error(p, n->cdr->car); 3474 void_expr_error(p, n->cdr->cdr); 3475 break; 3476 case NODE_BEGIN: 3477 if (n->cdr) { 3478 while (n->cdr) { 3479 n = n->cdr; 3480 } 3481 void_expr_error(p, n->car); 3482 } 3483 break; 3484 default: 3485 break; 3383 3486 } 3384 3487 } … … 3469 3572 c0 = nextc(p); 3470 3573 if (c0 == -1) return c0; /* do not skip partial EOF */ 3574 if (c0 >= 0) --p->column; 3471 3575 list = push(list, (node*)(intptr_t)c0); 3472 3576 } while(n--); … … 3517 3621 for (;;) { 3518 3622 c = nextc(p); 3519 if (c < 0) return c;3623 if (c < 0) return FALSE; 3520 3624 if (c == '\n') { 3521 3625 p->lineno++; … … 3547 3651 newtok(parser_state *p) 3548 3652 { 3549 p->bidx = 0; 3653 if (p->tokbuf != p->buf) { 3654 mrb_free(p->mrb, p->tokbuf); 3655 p->tokbuf = p->buf; 3656 p->tsiz = MRB_PARSER_TOKBUF_SIZE; 3657 } 3658 p->tidx = 0; 3550 3659 return p->column - 1; 3551 3660 } … … 3555 3664 { 3556 3665 char utf8[4]; 3557 unsignedlen;3666 int i, len; 3558 3667 3559 3668 /* mrb_assert(-0x10FFFF <= c && c <= 0xFF); */ … … 3589 3698 } 3590 3699 } 3591 if (p->bidx+len <= MRB_PARSER_BUF_SIZE) { 3592 unsigned i; 3593 for (i = 0; i < len; i++) { 3594 p->buf[p->bidx++] = utf8[i]; 3595 } 3700 if (p->tidx+len >= p->tsiz) { 3701 if (p->tsiz >= MRB_PARSER_TOKBUF_MAX) { 3702 p->tidx += len; 3703 return; 3704 } 3705 p->tsiz *= 2; 3706 if (p->tokbuf == p->buf) { 3707 p->tokbuf = (char*)mrb_malloc(p->mrb, p->tsiz); 3708 memcpy(p->tokbuf, p->buf, MRB_PARSER_TOKBUF_SIZE); 3709 } 3710 else { 3711 p->tokbuf = (char*)mrb_realloc(p->mrb, p->tokbuf, p->tsiz); 3712 } 3713 } 3714 for (i = 0; i < len; i++) { 3715 p->tokbuf[p->tidx++] = utf8[i]; 3596 3716 } 3597 3717 } … … 3600 3720 toklast(parser_state *p) 3601 3721 { 3602 return p-> buf[p->bidx-1];3722 return p->tokbuf[p->tidx-1]; 3603 3723 } 3604 3724 … … 3606 3726 tokfix(parser_state *p) 3607 3727 { 3608 int i = p->bidx, imax = MRB_PARSER_BUF_SIZE - 1; 3609 3610 if (i > imax) { 3611 i = imax; 3728 if (p->tidx >= MRB_PARSER_TOKBUF_MAX) { 3729 p->tidx = MRB_PARSER_TOKBUF_MAX-1; 3612 3730 yyerror(p, "string too long (truncated)"); 3613 3731 } 3614 p-> buf[i] = '\0';3732 p->tokbuf[p->tidx] = '\0'; 3615 3733 } 3616 3734 … … 3618 3736 tok(parser_state *p) 3619 3737 { 3620 return p-> buf;3738 return p->tokbuf; 3621 3739 } 3622 3740 … … 3624 3742 toklen(parser_state *p) 3625 3743 { 3626 return p-> bidx;3744 return p->tidx; 3627 3745 } 3628 3746 … … 3667 3785 3668 3786 return retval; 3787 } 3788 3789 static int32_t 3790 read_escape_unicode(parser_state *p, int limit) 3791 { 3792 int32_t c; 3793 int buf[9]; 3794 int i; 3795 3796 /* Look for opening brace */ 3797 i = 0; 3798 buf[0] = nextc(p); 3799 if (buf[0] < 0) goto eof; 3800 if (ISXDIGIT(buf[0])) { 3801 /* \uxxxx form */ 3802 for (i=1; i<limit; i++) { 3803 buf[i] = nextc(p); 3804 if (buf[i] < 0) goto eof; 3805 if (!ISXDIGIT(buf[i])) { 3806 pushback(p, buf[i]); 3807 break; 3808 } 3809 } 3810 } 3811 else { 3812 pushback(p, buf[0]); 3813 } 3814 c = scan_hex(buf, i, &i); 3815 if (i == 0) { 3816 eof: 3817 yyerror(p, "Invalid escape character syntax"); 3818 return -1; 3819 } 3820 if (c < 0 || c > 0x10FFFF || (c & 0xFFFFF800) == 0xD800) { 3821 yyerror(p, "Invalid Unicode code point"); 3822 return -1; 3823 } 3824 return c; 3669 3825 } 3670 3826 … … 3741 3897 3742 3898 case 'u': /* Unicode */ 3743 { 3744 int buf[9]; 3745 int i; 3746 3747 /* Look for opening brace */ 3748 i = 0; 3749 buf[0] = nextc(p); 3750 if (buf[0] < 0) goto eof; 3751 if (buf[0] == '{') { 3899 if (peek(p, '{')) { 3752 3900 /* \u{xxxxxxxx} form */ 3753 for (i=0; i<9; i++) { 3754 buf[i] = nextc(p); 3755 if (buf[i] < 0) goto eof; 3756 if (buf[i] == '}') { 3757 break; 3758 } 3759 else if (!ISXDIGIT(buf[i])) { 3760 yyerror(p, "Invalid escape character syntax"); 3761 pushback(p, buf[i]); 3762 return 0; 3763 } 3764 } 3765 } 3766 else if (ISXDIGIT(buf[0])) { 3767 /* \uxxxx form */ 3768 for (i=1; i<4; i++) { 3769 buf[i] = nextc(p); 3770 if (buf[i] < 0) goto eof; 3771 if (!ISXDIGIT(buf[i])) { 3772 pushback(p, buf[i]); 3773 break; 3774 } 3775 } 3901 nextc(p); 3902 c = read_escape_unicode(p, 8); 3903 if (c < 0) return 0; 3904 if (nextc(p) != '}') goto eof; 3776 3905 } 3777 3906 else { 3778 pushback(p, buf[0]); 3779 } 3780 c = scan_hex(buf, i, &i); 3781 if (i == 0) { 3782 yyerror(p, "Invalid escape character syntax"); 3783 return 0; 3784 } 3785 if (c < 0 || c > 0x10FFFF || (c & 0xFFFFF800) == 0xD800) { 3786 yyerror(p, "Invalid Unicode code point"); 3787 return 0; 3788 } 3789 } 3907 c = read_escape_unicode(p, 4); 3908 if (c < 0) return 0; 3909 } 3790 3910 return -c; 3791 3911 … … 3845 3965 int end = (intptr_t)p->lex_strterm->cdr->cdr->cdr; 3846 3966 parser_heredoc_info *hinf = (type & STR_FUNC_HEREDOC) ? parsing_heredoc_inf(p) : NULL; 3847 3967 int cmd_state = p->cmd_start; 3968 3969 if (beg == 0) beg = -3; /* should never happen */ 3970 if (end == 0) end = -3; 3848 3971 newtok(p); 3849 3972 while ((c = nextc(p)) != end || nest_level != 0) { … … 3867 3990 } 3868 3991 if ((len-1 == hinf->term_len) && (strncmp(s, hinf->term, len-1) == 0)) { 3869 return tHEREDOC_END; 3992 if (c < 0) { 3993 p->parsing_heredoc = NULL; 3994 } 3995 else { 3996 return tHEREDOC_END; 3997 } 3870 3998 } 3871 3999 } … … 3876 4004 return 0; 3877 4005 } 3878 yylval.nd = new_str(p, tok(p), toklen(p));4006 pylval.nd = new_str(p, tok(p), toklen(p)); 3879 4007 return tHD_STRING_MID; 3880 4008 } … … 3908 4036 tokadd(p, c); 3909 4037 } 4038 else if (c == 'u' && peek(p, '{')) { 4039 /* \u{xxxx xxxx xxxx} form */ 4040 nextc(p); 4041 while (1) { 4042 do c = nextc(p); while (ISSPACE(c)); 4043 if (c == '}') break; 4044 pushback(p, c); 4045 c = read_escape_unicode(p, 8); 4046 if (c < 0) break; 4047 tokadd(p, -c); 4048 } 4049 if (hinf) 4050 hinf->line_head = FALSE; 4051 } 3910 4052 else { 3911 4053 pushback(p, c); … … 3935 4077 p->lstate = EXPR_BEG; 3936 4078 p->cmd_start = TRUE; 3937 yylval.nd = new_str(p, tok(p), toklen(p));4079 pylval.nd = new_str(p, tok(p), toklen(p)); 3938 4080 if (hinf) { 3939 4081 hinf->line_head = FALSE; … … 3965 4107 pushback(p, c); 3966 4108 tokfix(p); 3967 yylval.nd = new_str(p, tok(p), toklen(p));4109 pylval.nd = new_str(p, tok(p), toklen(p)); 3968 4110 return tSTRING_MID; 3969 4111 } 4112 } 4113 if (c == '\n') { 4114 p->lineno++; 4115 p->column = 0; 3970 4116 } 3971 4117 tokadd(p, c); … … 3977 4123 3978 4124 if (type & STR_FUNC_XQUOTE) { 3979 yylval.nd = new_xstr(p, tok(p), toklen(p));4125 pylval.nd = new_xstr(p, tok(p), toklen(p)); 3980 4126 return tXSTRING; 3981 4127 } … … 4019 4165 if (flag > flags) { 4020 4166 dup = strndup(flags, (size_t)(flag - flags)); 4021 } else { 4167 } 4168 else { 4022 4169 dup = NULL; 4023 4170 } 4024 4171 if (enc) { 4025 4172 encp = strndup(&enc, 1); 4026 } else { 4173 } 4174 else { 4027 4175 encp = NULL; 4028 4176 } 4029 yylval.nd = new_regx(p, s, dup, encp);4177 pylval.nd = new_regx(p, s, dup, encp); 4030 4178 4031 4179 return tREGEXP; 4032 4180 } 4033 4034 yylval.nd = new_str(p, tok(p), toklen(p)); 4181 pylval.nd = new_str(p, tok(p), toklen(p)); 4182 if (IS_LABEL_POSSIBLE()) { 4183 if (IS_LABEL_SUFFIX(0)) { 4184 p->lstate = EXPR_BEG; 4185 nextc(p); 4186 return tLABEL_END; 4187 } 4188 } 4189 4035 4190 return tSTRING; 4036 4191 } … … 4102 4257 p->lstate = EXPR_END; 4103 4258 4104 yylval.nd = newnode;4259 pylval.nd = newnode; 4105 4260 return tHEREDOC_BEG; 4106 4261 } … … 4206 4361 if ((c = nextc(p)) == '*') { 4207 4362 if ((c = nextc(p)) == '=') { 4208 yylval.id = intern("**",2);4363 pylval.id = intern("**",2); 4209 4364 p->lstate = EXPR_BEG; 4210 4365 return tOP_ASGN; … … 4215 4370 else { 4216 4371 if (c == '=') { 4217 yylval.id = intern_c('*');4372 pylval.id = intern_c('*'); 4218 4373 p->lstate = EXPR_BEG; 4219 4374 return tOP_ASGN; … … 4331 4486 if (c == '<') { 4332 4487 if ((c = nextc(p)) == '=') { 4333 yylval.id = intern("<<",2);4488 pylval.id = intern("<<",2); 4334 4489 p->lstate = EXPR_BEG; 4335 4490 return tOP_ASGN; … … 4353 4508 if (c == '>') { 4354 4509 if ((c = nextc(p)) == '=') { 4355 yylval.id = intern(">>",2);4510 pylval.id = intern(">>",2); 4356 4511 p->lstate = EXPR_BEG; 4357 4512 return tOP_ASGN; … … 4450 4605 } 4451 4606 tokfix(p); 4452 yylval.nd = new_str(p, tok(p), toklen(p));4607 pylval.nd = new_str(p, tok(p), toklen(p)); 4453 4608 p->lstate = EXPR_END; 4454 4609 return tCHAR; … … 4458 4613 p->lstate = EXPR_BEG; 4459 4614 if ((c = nextc(p)) == '=') { 4460 yylval.id = intern("&&",2);4615 pylval.id = intern("&&",2); 4461 4616 p->lstate = EXPR_BEG; 4462 4617 return tOP_ASGN; … … 4465 4620 return tANDOP; 4466 4621 } 4622 else if (c == '.') { 4623 p->lstate = EXPR_DOT; 4624 return tANDDOT; 4625 } 4467 4626 else if (c == '=') { 4468 yylval.id = intern_c('&');4627 pylval.id = intern_c('&'); 4469 4628 p->lstate = EXPR_BEG; 4470 4629 return tOP_ASGN; … … 4493 4652 p->lstate = EXPR_BEG; 4494 4653 if ((c = nextc(p)) == '=') { 4495 yylval.id = intern("||",2);4654 pylval.id = intern("||",2); 4496 4655 p->lstate = EXPR_BEG; 4497 4656 return tOP_ASGN; … … 4501 4660 } 4502 4661 if (c == '=') { 4503 yylval.id = intern_c('|');4662 pylval.id = intern_c('|'); 4504 4663 p->lstate = EXPR_BEG; 4505 4664 return tOP_ASGN; … … 4525 4684 } 4526 4685 if (c == '=') { 4527 yylval.id = intern_c('+');4686 pylval.id = intern_c('+'); 4528 4687 p->lstate = EXPR_BEG; 4529 4688 return tOP_ASGN; … … 4553 4712 } 4554 4713 if (c == '=') { 4555 yylval.id = intern_c('-');4714 pylval.id = intern_c('-'); 4556 4715 p->lstate = EXPR_BEG; 4557 4716 return tOP_ASGN; … … 4627 4786 } 4628 4787 else if (nondigit) goto trailing_uc; 4629 yylval.nd = new_int(p, tok(p), 16);4788 pylval.nd = new_int(p, tok(p), 16); 4630 4789 return tINTEGER; 4631 4790 } … … 4651 4810 } 4652 4811 else if (nondigit) goto trailing_uc; 4653 yylval.nd = new_int(p, tok(p), 2);4812 pylval.nd = new_int(p, tok(p), 2); 4654 4813 return tINTEGER; 4655 4814 } … … 4675 4834 } 4676 4835 else if (nondigit) goto trailing_uc; 4677 yylval.nd = new_int(p, tok(p), 10);4836 pylval.nd = new_int(p, tok(p), 10); 4678 4837 return tINTEGER; 4679 4838 } … … 4708 4867 tokfix(p); 4709 4868 if (nondigit) goto trailing_uc; 4710 yylval.nd = new_int(p, tok(p), 8);4869 pylval.nd = new_int(p, tok(p), 8); 4711 4870 return tINTEGER; 4712 4871 } … … 4725 4884 else { 4726 4885 pushback(p, c); 4727 yylval.nd = new_int(p, "0", 10);4886 pylval.nd = new_int(p, "0", 10); 4728 4887 return tINTEGER; 4729 4888 } … … 4801 4960 4802 4961 errno = 0; 4803 d = strtod(tok(p), &endp);4962 d = mrb_float_read(tok(p), &endp); 4804 4963 if (d == 0 && endp == tok(p)) { 4805 4964 yywarning_s(p, "corrupted float value %s", tok(p)); … … 4809 4968 errno = 0; 4810 4969 } 4811 yylval.nd = new_float(p, tok(p));4970 pylval.nd = new_float(p, tok(p)); 4812 4971 return tFLOAT; 4813 4972 } 4814 yylval.nd = new_int(p, tok(p), 10);4973 pylval.nd = new_int(p, tok(p), 10); 4815 4974 return tINTEGER; 4816 4975 } … … 4854 5013 } 4855 5014 if ((c = nextc(p)) == '=') { 4856 yylval.id = intern_c('/');5015 pylval.id = intern_c('/'); 4857 5016 p->lstate = EXPR_BEG; 4858 5017 return tOP_ASGN; … … 4873 5032 case '^': 4874 5033 if ((c = nextc(p)) == '=') { 4875 yylval.id = intern_c('^');5034 pylval.id = intern_c('^'); 4876 5035 p->lstate = EXPR_BEG; 4877 5036 return tOP_ASGN; … … 5047 5206 } 5048 5207 if ((c = nextc(p)) == '=') { 5049 yylval.id = intern_c('%');5208 pylval.id = intern_c('%'); 5050 5209 p->lstate = EXPR_BEG; 5051 5210 return tOP_ASGN; … … 5101 5260 tokadd(p, c); 5102 5261 tokfix(p); 5103 yylval.id = intern_cstr(tok(p));5262 pylval.id = intern_cstr(tok(p)); 5104 5263 return tGVAR; 5105 5264 … … 5111 5270 gvar: 5112 5271 tokfix(p); 5113 yylval.id = intern_cstr(tok(p));5272 pylval.id = intern_cstr(tok(p)); 5114 5273 return tGVAR; 5115 5274 … … 5123 5282 goto gvar; 5124 5283 } 5125 yylval.nd = new_back_ref(p, c);5284 pylval.nd = new_back_ref(p, c); 5126 5285 return tBACK_REF; 5127 5286 … … 5142 5301 return 0; 5143 5302 } 5144 yylval.nd = new_nth_ref(p, (int)n);5303 pylval.nd = new_nth_ref(p, (int)n); 5145 5304 } 5146 5305 return tNTH_REF; … … 5166 5325 } 5167 5326 if (c < 0) { 5168 if (p-> bidx == 1) {5327 if (p->tidx == 1) { 5169 5328 yyerror(p, "incomplete instance variable syntax"); 5170 5329 } … … 5175 5334 } 5176 5335 else if (isdigit(c)) { 5177 if (p-> bidx == 1) {5336 if (p->tidx == 1) { 5178 5337 yyerror_i(p, "'@%c' is not allowed as an instance variable name", c); 5179 5338 } … … 5270 5429 nextc(p); 5271 5430 tokfix(p); 5272 yylval.id = intern_cstr(tok(p));5431 pylval.id = intern_cstr(tok(p)); 5273 5432 return tLABEL; 5274 5433 } … … 5281 5440 if (kw) { 5282 5441 enum mrb_lex_state_enum state = p->lstate; 5283 yylval.num = p->lineno;5442 pylval.num = p->lineno; 5284 5443 p->lstate = kw->state; 5285 5444 if (state == EXPR_FNAME) { 5286 yylval.id = intern_cstr(kw->name);5445 pylval.id = intern_cstr(kw->name); 5287 5446 return kw->id[0]; 5288 5447 } … … 5331 5490 mrb_sym ident = intern_cstr(tok(p)); 5332 5491 5333 yylval.id = ident;5492 pylval.id = ident; 5334 5493 #if 0 5335 5494 if (last_state != EXPR_DOT && islower(tok(p)[0]) && lvar_defined(ident)) { … … 5396 5555 mrb_parser_parse(parser_state *p, mrbc_context *c) 5397 5556 { 5398 struct mrb_jmpbuf buf ;5399 p->jmp = &buf ;5557 struct mrb_jmpbuf buf1; 5558 p->jmp = &buf1; 5400 5559 5401 5560 MRB_TRY(p->jmp) { 5561 int n; 5402 5562 5403 5563 p->cmd_start = TRUE; … … 5407 5567 5408 5568 parser_init_cxt(p, c); 5409 yyparse(p); 5569 5570 if (p->mrb->jmp) { 5571 n = yyparse(p); 5572 } 5573 else { 5574 struct mrb_jmpbuf buf2; 5575 5576 p->mrb->jmp = &buf2; 5577 MRB_TRY(p->mrb->jmp) { 5578 n = yyparse(p); 5579 } 5580 MRB_CATCH(p->mrb->jmp) { 5581 p->nerr++; 5582 } 5583 MRB_END_EXC(p->mrb->jmp); 5584 p->mrb->jmp = 0; 5585 } 5586 if (n != 0 || p->nerr > 0) { 5587 p->tree = 0; 5588 return; 5589 } 5410 5590 if (!p->tree) { 5411 5591 p->tree = new_nil(p); … … 5415 5595 mrb_parser_dump(p->mrb, p->tree, 0); 5416 5596 } 5417 5418 5597 } 5419 5598 MRB_CATCH(p->jmp) { … … 5443 5622 5444 5623 p->s = p->send = NULL; 5445 #ifndef MRB_DIS BLE_STDIO5624 #ifndef MRB_DISABLE_STDIO 5446 5625 p->f = NULL; 5447 5626 #endif … … 5456 5635 yydebug = 1; 5457 5636 #endif 5637 p->tsiz = MRB_PARSER_TOKBUF_SIZE; 5638 p->tokbuf = p->buf; 5458 5639 5459 5640 p->lex_strterm = NULL; … … 5470 5651 MRB_API void 5471 5652 mrb_parser_free(parser_state *p) { 5653 if (p->tokbuf != p->buf) { 5654 mrb_free(p->mrb, p->tokbuf); 5655 } 5472 5656 mrb_pool_close(p->pool); 5473 5657 } … … 5482 5666 mrbc_context_free(mrb_state *mrb, mrbc_context *cxt) 5483 5667 { 5668 mrb_free(mrb, cxt->filename); 5484 5669 mrb_free(mrb, cxt->syms); 5485 5670 mrb_free(mrb, cxt); … … 5491 5676 if (s) { 5492 5677 int len = strlen(s); 5493 char *p = (char *)mrb_ alloca(mrb, len + 1);5678 char *p = (char *)mrb_malloc(mrb, len + 1); 5494 5679 5495 5680 memcpy(p, s, len + 1); 5681 if (c->filename) { 5682 mrb_free(mrb, c->filename); 5683 } 5496 5684 c->filename = p; 5497 5685 } … … 5578 5766 } 5579 5767 5580 staticmrb_value5581 load_exec(mrb_state *mrb,parser_state *p, mrbc_context *c)5768 MRB_API mrb_value 5769 mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c) 5582 5770 { 5583 5771 struct RClass *target = mrb->object_class; … … 5601 5789 } 5602 5790 else { 5603 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error")); 5791 if (mrb->exc == NULL) { 5792 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error")); 5793 } 5604 5794 mrb_parser_free(p); 5605 5795 return mrb_undef_value(); … … 5609 5799 mrb_parser_free(p); 5610 5800 if (proc == NULL) { 5611 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error")); 5801 if (mrb->exc == NULL) { 5802 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error")); 5803 } 5612 5804 return mrb_undef_value(); 5613 5805 } … … 5629 5821 mrb->c->ci->target_class = target; 5630 5822 } 5631 v = mrb_top level_run_keep(mrb, proc, keep);5823 v = mrb_top_run(mrb, proc, mrb_top_self(mrb), keep); 5632 5824 if (mrb->exc) return mrb_nil_value(); 5633 5825 return v; … … 5638 5830 mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c) 5639 5831 { 5640 return load_exec(mrb, mrb_parse_file(mrb, f, c), c);5832 return mrb_load_exec(mrb, mrb_parse_file(mrb, f, c), c); 5641 5833 } 5642 5834 … … 5651 5843 mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *c) 5652 5844 { 5653 return load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c);5845 return mrb_load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c); 5654 5846 } 5655 5847 … … 5805 5997 dump_recur(mrb, n->car, offset+2); 5806 5998 } 5807 n = n->cdr; 5808 if (n) { 5999 if (n->cdr) { 5809 6000 dump_prefix(n, offset+1); 5810 printf("blk=&%s\n", mrb_sym2name(mrb, sym(n )));6001 printf("blk=&%s\n", mrb_sym2name(mrb, sym(n->cdr))); 5811 6002 } 5812 6003 } … … 5946 6137 case NODE_FCALL: 5947 6138 case NODE_CALL: 5948 printf("NODE_CALL:\n"); 6139 case NODE_SCALL: 6140 switch (nodetype) { 6141 case NODE_FCALL: 6142 printf("NODE_FCALL:\n"); break; 6143 case NODE_CALL: 6144 printf("NODE_CALL(.):\n"); break; 6145 case NODE_SCALL: 6146 printf("NODE_SCALL(&.):\n"); break; 6147 default: 6148 break; 6149 } 5949 6150 mrb_parser_dump(mrb, tree->car, offset+1); 5950 6151 dump_prefix(tree, offset+1); … … 6154 6355 6155 6356 case NODE_NTH_REF: 6156 printf("NODE_NTH_REF: $% d\n", (int)(intptr_t)tree);6357 printf("NODE_NTH_REF: $%" MRB_PRId "\n", (mrb_int)(intptr_t)tree); 6157 6358 break; 6158 6359 … … 6206 6407 dump_prefix(tree, offset); 6207 6408 printf("tail: %s\n", (char*)tree->cdr->cdr->car); 6208 dump_prefix(tree, offset); 6209 printf("opt: %s\n", (char*)tree->cdr->cdr->cdr); 6409 if (tree->cdr->cdr->cdr->car) { 6410 dump_prefix(tree, offset); 6411 printf("opt: %s\n", (char*)tree->cdr->cdr->cdr->car); 6412 } 6413 if (tree->cdr->cdr->cdr->cdr) { 6414 dump_prefix(tree, offset); 6415 printf("enc: %s\n", (char*)tree->cdr->cdr->cdr->cdr); 6416 } 6210 6417 break; 6211 6418 6212 6419 case NODE_SYM: 6213 printf("NODE_SYM :%s\n", mrb_sym2name(mrb, sym(tree))); 6420 printf("NODE_SYM :%s (%d)\n", mrb_sym2name(mrb, sym(tree)), 6421 (int)(intptr_t)tree); 6214 6422 break; 6215 6423 … … 6425 6633 6426 6634 case NODE_HEREDOC: 6427 printf("NODE_HEREDOC :\n");6428 mrb_parser_dump(mrb, ((parser_heredoc_info*)tree)->doc, offset+1);6635 printf("NODE_HEREDOC (<<%s):\n", ((parser_heredoc_info*)tree)->term); 6636 dump_recur(mrb, ((parser_heredoc_info*)tree)->doc, offset+1); 6429 6637 break; 6430 6638
Note:
See TracChangeset
for help on using the changeset viewer.