| 1 | # handle sqrt(-1) and log of negatives (make complexes) |
|
|
| 2 | # do division by zero and log of zero checks in compound functions |
|
|
| 3 | # add context flags for various reduction checks |
|
|
| 4 | # make context flag for reduction of constants |
|
|
| 5 | # make reduce have reduce patterns as parameters |
|
|
| 6 | # more reduce patterns |
|
|
| 7 | # make operator strings customizable (reduce, and other places they are used) |
|
|
| 8 | # add parens alternately as () and []? |
|
|
| 9 | |
|
|
| 10 | package Parser; |
1 | package Parser; |
| 11 | my $pkg = "Parser"; |
2 | my $pkg = "Parser"; |
| 12 | |
3 | |
| 13 | use strict; |
4 | use strict; |
| 14 | #use Carp; |
5 | #use Carp; |
| … | |
… | |
| 22 | sub new { |
13 | sub new { |
| 23 | my $self = shift; my $class = ref($self) || $self; |
14 | my $self = shift; my $class = ref($self) || $self; |
| 24 | my $string = shift; |
15 | my $string = shift; |
| 25 | my $math = bless { |
16 | my $math = bless { |
| 26 | string => undef, |
17 | string => undef, |
| 27 | tokens => [], |
18 | tokens => [], tree => undef, |
| 28 | tree => undef, |
|
|
| 29 | variables => {}, values => {}, |
19 | variables => {}, values => {}, |
| 30 | context => Parser::Context->current, |
20 | context => Parser::Context->current, |
| 31 | error => 0, errorPos => undef, |
|
|
| 32 | message => '', |
|
|
| 33 | }, $class; |
21 | }, $class; |
| 34 | if (ref($string) =~ m/^(Parser|Value::Formula)/) { |
22 | if (ref($string) =~ m/^(Parser|Value::Formula)/) { |
| 35 | my $tree = $string; $tree = $tree->{tree} if exists $tree->{tree}; |
23 | my $tree = $string; $tree = $tree->{tree} if exists $tree->{tree}; |
| 36 | $math->{tree} = $tree->copy($math); |
24 | $math->{tree} = $tree->copy($math); |
| 37 | } elsif (ref($string) =~ m/^Value/) { |
25 | } elsif (ref($string) =~ m/^Value/) { |
| … | |
… | |
| 652 | unless Parser::Item::typeMatch($type,$variables->{$x}{type}); |
640 | unless Parser::Item::typeMatch($type,$variables->{$x}{type}); |
| 653 | $self->{values}{$x} = $value; |
641 | $self->{values}{$x} = $value; |
| 654 | } |
642 | } |
| 655 | } |
643 | } |
| 656 | |
644 | |
|
|
645 | |
| 657 | ######################################################################### |
646 | ######################################################################### |
| 658 | ######################################################################### |
647 | ######################################################################### |
| 659 | # |
648 | # |
| 660 | # Load the sub-classes and Value.pm |
649 | # Load the sub-classes and Value.pm |
| 661 | # |
650 | # |
| … | |
… | |
| 664 | use Value; |
653 | use Value; |
| 665 | use Value::Formula; |
654 | use Value::Formula; |
| 666 | use Parser::Context; |
655 | use Parser::Context; |
| 667 | # use Parser::Differentiation; |
656 | # use Parser::Differentiation; |
| 668 | |
657 | |
|
|
658 | ########################################################################### |
|
|
659 | ########################################################################### |
|
|
660 | # |
|
|
661 | # To Do: |
|
|
662 | # |
|
|
663 | # handle sqrt(-1) and log of negatives (make complexes) |
|
|
664 | # do division by zero and log of zero checks in compound functions |
|
|
665 | # add context flags for various reduction checks |
|
|
666 | # make context flag for reduction of constants |
|
|
667 | # make reduce have reduce patterns as parameters |
|
|
668 | # more reduce patterns |
|
|
669 | # make operator strings customizable (reduce, and other places they are used) |
|
|
670 | # add parens alternately as () and []? |
|
|
671 | # eliminate Complex class (it only gets used by main::Complex() when the |
|
|
672 | # arguments are formulas; use $a + $b*i and let overload handle it instead.) |
|
|
673 | # |
| 669 | ######################################################################### |
674 | ######################################################################### |
| 670 | |
675 | |
| 671 | 1; |
676 | 1; |
| 672 | |
677 | |