Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- print "0\n";
- while (<>) {
- chomp;
- my @stack;
- # assuming only one digit numbers
- foreach my $tok (reverse split( / */ )) {
- if ($tok =~ m#[0-9]#) {
- print "$tok ";
- } elsif ($tok eq '(') {
- # parsing backwards, so ( is close, and ( is open
- while ((my $pop = pop @stack) ne ')') {
- print $pop;
- }
- } else {
- push( @stack, $tok );
- }
- }
- print reverse( @stack ), "+\n";
- }
- print "p\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement