Project

General

Profile

Feature #8430 ยป ratio_lit.patch

A patch for the rational number literal - takuto_h (Takuto Hayashi), 08/01/2013 04:53 PM

View differences:

parse.y
keyword__ENCODING__
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <node> tINTEGER tFLOAT tSTRING_CONTENT tCHAR
%token <node> tINTEGER tFLOAT tRATIONAL tSTRING_CONTENT tCHAR
%token <node> tNTH_REF tBACK_REF
%token <num> tREGEXP_END
......
$$ = dispatch2(unary, ripper_intern("-@"), $$);
%*/
}
| tUMINUS_NUM tRATIONAL tPOW arg
{
/*%%%*/
$$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0);
/*%
$$ = dispatch3(binary, $2, ripper_intern("**"), $4);
$$ = dispatch2(unary, ripper_intern("-@"), $$);
%*/
}
| tUPLUS arg
{
/*%%%*/
......
numeric : tINTEGER
| tFLOAT
| tRATIONAL
| tUMINUS_NUM tINTEGER %prec tLOWEST
{
/*%%%*/
......
$$ = dispatch2(unary, ripper_intern("-@"), $2);
%*/
}
| tUMINUS_NUM tRATIONAL %prec tLOWEST
{
/*%%%*/
$$ = NEW_CALL($2, tUMINUS, 0);
/*%
$$ = dispatch2(unary, ripper_intern("-@"), $2);
%*/
}
;
user_variable : tIDENTIFIER
......
}
decode_num:
pushback(c);
if (nondigit) {
char tmp[30];
trailing_uc:
......
errno = 0;
}
set_yylval_literal(DBL2NUM(d));
pushback(c);
return tFLOAT;
}
if (c == 'r') {
NODE *args = NEW_ARRAY(NEW_STR(rb_str_new_cstr(tok())));
NODE *fcall = NEW_FCALL(rb_intern("Rational"), args);
set_yylval_node(fcall);
return tRATIONAL;
}
set_yylval_literal(rb_cstr_to_inum(tok(), 10, FALSE));
pushback(c);
return tINTEGER;
}
    (1-1/1)