Acme-AlgebraicToRPN

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

Acme-AlgebraicToRPN

Converts an algebraic equation to RPN (reverse polish notation). Virtually
infinite nesting of parenthesis. Allows functions, provided the function
is called like this:

    foo(...)

INSTALLATION

To install this module, run the following commands:

    perl Makefile.PL
    make
    make test
    make install


SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the perldoc command.

    perldoc Acme::AlgebraicToRPN

You can also look for information at:

    Search CPAN
        http://search.cpan.org/dist/Acme-AlgebraicToRPN

    CPAN Request Tracker:
        http://rt.cpan.org/NoAuth/Bugs.html?Dist=Acme-AlgebraicToRPN

lib/Acme/AlgebraicToRPN.pm  view on Meta::CPAN

=head1 BUGS

Please report any bugs or feature requests to
C<bug-acme-algebraictorpn at rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-AlgebraicToRPN>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Acme::AlgebraicToRPN

You can also look for information at:

=over 4

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Acme-AlgebraicToRPN>

lib/Acme/AlgebraicToRPN.pm  view on Meta::CPAN

    my @result = ./_Cleanup();
    # reset, ready for next equation
    $.stack = [];
    return @result;
}

=head2 B<rpn_as_string>

  $stack = $al->rpn($expr);

Same as B<rpn>, but returns as a comma-separated list. Split on
commas, and you have your stack to be processed.

=cut

sub rpn_as_string {
    my ($self, $algebraic) = @_;
    my @result = ./rpn($algebraic);
    return join(",", @result);
}

sub _Cleanup {

lib/Acme/AlgebraicToRPN.pm  view on Meta::CPAN

            push(@{$.stack}, $L);
        }
    }

    if ($expr =~ /(\w+)($RE{balanced}{-parens=>'()'})(.*)/) {
        my $op = $1;
        my $p  = $2;
        my $r  = $3;
        my $core = substr($p, 1, length($p)-2);
        if (defined $.userFunc && defined $.userFunc{$op}) {
            # count # of commas in arg list
            my $na = $core =~ tr/,/,/;
            # bump by one
            $na++;
            # add # of aguments on
            $core = qq($core,$na);
        }
        ./_Eval($core);
        push(@{$.stack}, $core) 
            unless $core =~ /$RE{balanced}{-parens=>'()'}/;
        push(@{$.stack}, $op);



( run in 1.714 second using v1.01-cache-2.11-cpan-d8267643d1d )