line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Greple::frame::RPN; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
911
|
use v5.14; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
151
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw( rpn_calc ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @operator = sort { length $b <=> length $a } split /[,\s]+/, <<'END'; |
11
|
|
|
|
|
|
|
+,ADD ++,INCR -,SUB --,DECR *,MUL /,DIV %,MOD POW SQRT |
12
|
|
|
|
|
|
|
SIN COS TAN |
13
|
|
|
|
|
|
|
LOG EXP |
14
|
|
|
|
|
|
|
ABS INT |
15
|
|
|
|
|
|
|
&,AND |,OR !,NOT XOR ~ |
16
|
|
|
|
|
|
|
<,LT <=,LE =,==,EQ >,GT >=,GE !=,NE |
17
|
|
|
|
|
|
|
IF |
18
|
|
|
|
|
|
|
DUP EXCH POP |
19
|
|
|
|
|
|
|
MIN MAX |
20
|
|
|
|
|
|
|
TIME |
21
|
|
|
|
|
|
|
RAND LRAND |
22
|
|
|
|
|
|
|
END |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $operator_re = join '|', map "\Q$_", @operator; |
25
|
|
|
|
|
|
|
my $term_re = qr/(?:\d*\.)?\d+|$operator_re/i; |
26
|
|
|
|
|
|
|
my $rpn_re = qr/(?: $term_re ,* ){2,}/xi; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub rpn_calc { |
29
|
1
|
|
|
1
|
|
458
|
use Math::RPN (); |
|
1
|
|
|
|
|
2238
|
|
|
1
|
|
|
|
|
105
|
|
30
|
0
|
|
|
0
|
0
|
|
my @terms = map { /$term_re/g } @_; |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my @ans = do { local $_; Math::RPN::rpn @terms }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
0
|
0
|
0
|
|
|
|
if (@ans == 1 && defined $ans[0] && $ans[0] !~ /[^\.\d]/) { |
|
|
|
0
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$ans[0]; |
34
|
|
|
|
|
|
|
} else { |
35
|
0
|
|
|
|
|
|
return undef; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |