Acme-AlgebraicToRPN

 view release on metacpan or  search on metacpan

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

=head1 SYNOPSIS

  $rpn = Acme::AlgebraicToRPN->new;
  @RPN = $rpn->eval($equation);

=head1 DESCRIPTION

Given a string with algebraic notation, convert to RPN, which is
what any crappy dime store calculator needs to do anyway.

Doesn't really process anything, that's up to you. You will get an
array back with all of the variables and operations in RPN format.
So that 3+4 will come back as

    3
    4
    add

Possible future extensions will be to allow you to actually process
this via hooks that allow specifications of how to handle foreign
functions. But for my purposes, the array is good enough, as I am
passing this on to a C program to do some serious number crunching.

Additionally, you can specify (via the constructor) the names of
your own functions. See below.

=head1 ACKNOWLEDGEMENT

The Hewlett Packard Company and the HP 35, my first real calculator,

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

        );
    }
    return $self;
}

=head2 B<rpn>

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

Processes $expr (an algebraic format expression) and return the
stack necessary to process it. The stack consists entirely of
variables, constants and operations. For operations, be
prepared to handle (and others, see B<Math::Symbolic> documentation):

  negate
  add
  subtract
  multiply
  divide
  exponentiate
  sin

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

    # 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 {



( run in 0.329 second using v1.01-cache-2.11-cpan-8d75d55dd25 )