e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
RubyKaigie$B$N%-!<%N!<%H$G$bOC$7$^$7$?$,!"J#AG?t%j%F%i%k$r<B8=e(B
e$B$9$k%Q%C%A$r=q$-$^$7$?!#$3$l$rEv$F$k$H!"e(B
2i
2.0i
e$B$N$h$&$JI=8=$,2DG=$K$J$j$^$9!#$5$F!"$3$l$r<h$j9~$b$&$+$I$&$+e(B
e$B9M$($F$$$k$N$G$9$,!"8!F$$r<jEA$C$F$$$?$@$1$kJ}$O$$$i$C$7$c$$e(B
e$B$^$9$+!)e(B
e$B8!F$$9$Y$-$3$He(B
- e$B8_49@-$O$I$&$+!#Bg>fIW$N$O$:$@$,!"8+Mn$H$7$Oe(B
- ie$B$G$$$$$N$+!#e(BPythone$B$O$J$<$+e(Bje$B$@$,!#e(B
- e$BJ#AG?t2=$9$k%a%=%C%Ie(BNumeric#ie$B$OMW$i$J$$$+e(B
- e$BMW$k$J$i!"5u?te(B.ie$B$NCM$O2?$+!)e(B
e$BJ#AG?te(B.ie$B$NCM$O!)e(B
diff --git a/parse.y b/parse.y
index d311e13…3630c60 100644
— a/parse.y
+++ b/parse.y
@@ -655,14 +655,14 @@ static void token_info_pop(struct parser_params*,
const char *token);
keyword__ENCODING__
%token tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
-%token tINTEGER tFLOAT tSTRING_CONTENT tCHAR
+%token tINTEGER tFLOAT tCOMPLEX tSTRING_CONTENT tCHAR
%token tNTH_REF tBACK_REF
%token tREGEXP_END
%type singleton strings string string1 xstring regexp
%type string_contents xstring_contents string_content
%type words qwords word_list qword_list word
-%type literal numeric dsym cpath
+%type literal numeric num_lit dsym cpath
%type bodystmt compstmt stmts stmt expr arg primary command
command_call method_call
%type expr_value arg_value primary_value
%type if_tail opt_else case_body cases opt_rescue exc_list
exc_var opt_ensure
@@ -2063,16 +2063,7 @@ arg : lhs ‘=’ arg
$$ = dispatch3(binary, $1, ripper_intern("**"), $3);
%*/
}
- | tUMINUS_NUM tINTEGER tPOW arg
-
{
-
/*%%%*/
-
$$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0);
-
/*%
-
$$ = dispatch3(binary, $2, ripper_intern("**"), $4);
-
$$ = dispatch2(unary, ripper_intern("-@"), $$);
-
%*/
-
}
- | tUMINUS_NUM tFLOAT tPOW arg
- | tUMINUS_NUM num_lit tPOW arg
{
/%%%/
$$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0);
@@ -4092,17 +4083,13 @@ dsym : tSYMBEG xstring_contents tSTRING_END
}
;
-numeric : tINTEGER
+num_lit : tINTEGER
| tFLOAT
- | tUMINUS_NUM tINTEGER %prec tLOWEST
-
{
-
/*%%%*/
-
$$ = negate_lit($2);
-
/*%
-
$$ = dispatch2(unary, ripper_intern("-@"), $2);
-
%*/
-
}
- | tUMINUS_NUM tFLOAT %prec tLOWEST
- | tCOMPLEX
- ;
+numeric : num_lit
- | tUMINUS_NUM num_lit %prec tLOWEST
{
/%%%/
$$ = negate_lit($2);
@@ -6858,9 +6845,9 @@ parser_yylex(struct parser_params *parser)
case ‘0’: case ‘1’: case ‘2’: case ‘3’: case ‘4’:
case ‘5’: case ‘6’: case ‘7’: case ‘8’: case ‘9’:
{
-
int is_float, seen_point, seen_e, nondigit;
-
int is_float, seen_point, seen_e, nondigit, is_complex;
-
is_float = seen_point = seen_e = nondigit = 0;
-
is_float = seen_point = seen_e = nondigit = is_complex = 0; lex_state = EXPR_END; newtok(); if (c == '-' || c == '+') {
@@ -7046,6 +7033,10 @@ parser_yylex(struct parser_params *parser)
nondigit = c;
break;
-
case 'i':
-
is_complex++;
-
goto decode_complex;
-
default: goto decode_num;
}
@@ -7054,6 +7045,7 @@ parser_yylex(struct parser_params *parser)decode_num:
pushback©; -
decode_complex:
tokfix();
if (nondigit) {
char tmp[30];
@@ -7067,9 +7059,18 @@ parser_yylex(struct parser_params *parser)
rb_warningS(“Float %s out of range”, tok());
errno = 0;
} -
if (is_complex) {
-
set_yylval_literal(rb_complex_new(INT2FIX(0), DBL2NUM(d)));
-
return tCOMPLEX;
-
}
set_yylval_literal(DBL2NUM(d));
return tFLOAT;
} -
if (is_complex) {
-
set_yylval_literal(rb_complex_new(INT2FIX(0),
-
rb_cstr_to_inum(tok(), 10, Qfalse)));
-
return tCOMPLEX;
-
} set_yylval_literal(rb_cstr_to_inum(tok(), 10, Qfalse)); return tINTEGER;
}
@@ -8677,6 +8678,7 @@ negate_lit(NODE *node)
node->nd_lit = LONG2FIX(-FIX2LONG(node->nd_lit));
break;
case T_BIGNUM: -
case T_COMPLEX:
node->nd_lit = rb_funcall(node->nd_lit,tUMINUS,0,0);
break;
case T_FLOAT: