Parsing/Shunting-yard algorithm: Difference between revisions
m
→{{header|Raku}}: Undo bizarre single space indent that somebody found necessary to do
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: Undo bizarre single space indent that somebody found necessary to do) |
||
Line 4,087:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line> my %prec =
my %prec =▼
▲ '(' => 1;
▲ '-' => 'left';
my @inp = $prog.words;
▲ sub shunting-yard ($prog) {
my @res;▼
sub report($op) { printf "%25s %-7s %10s %s\n", ~@res, ~@ops, $op, ~@inp }
while @inp {
default {
last
reduce
shift
▲ reduce @ops.pop while @ops;
▲ }
▲ say shunting-yard '3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3';
{{out}}
<pre> reduce 3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3
|