Skip to content

Commit 05669d7

Browse files
committed
improvements and fixes in RPN.pl
* use .list to fix "for" iteration over an array reference. * properly handle the case when no input string argument is specified. * suppress the "Useless declaration of a has-scoped method" warnings from the latest rakudo.
1 parent d393e53 commit 05669d7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

interpreters/RPN.pl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
#
66
# USAGE: perl6 RPN.pl "5 4 + 3 / 5 3 - *"
77

8-
token Op { '+' || '-' || '*' || '/' };
9-
token Value { \d+[\.\d+]? };
10-
token Item { <Value> || <Op> };
11-
token Expr { [<Item> <ws>]+ };
8+
my token Op { '+' || '-' || '*' || '/' };
9+
my token Value { \d+[\.\d+]? };
10+
my token Item { <Value> || <Op> };
11+
my token Expr { [<Item> <ws>]+ };
1212

13-
my $str = @*ARGS[0];
13+
my $str = @*ARGS[0] // die "No input string specified";
1414

1515
if $str ~~ /^ <Expr> $/ {
1616
my @stack;
1717

18-
for $/<Expr><Item> -> $item {
18+
for $/<Expr><Item>.list -> $item {
1919
if $item<Value> {
2020
@stack.push($item<Value>);
2121
} else {

0 commit comments

Comments
 (0)