[system] / trunk / pg / lib / Parser.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/Parser.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2682 Revision 2796
4 4
5# 5#
6# Map class names to packages (added to Context, and 6# Map class names to packages (added to Context, and
7# can be overriden to customize the parser) 7# can be overriden to customize the parser)
8# 8#
9our %class = {Formula => 'Parser::Formula'}; 9our $class = {Formula => 'Parser::Formula'};
10
11#
12# Collect the default reduction flags for use in the context
13#
14our $reduce = {};
10 15
11################################################## 16##################################################
12# 17#
13# Parse a string and create a new Parser object 18# Parse a string and create a new Parser object
14# If the string is already a parsed object then copy the parse tree 19# If the string is already a parsed object then copy the parse tree
553} 558}
554 559
555################################################## 560##################################################
556# 561#
557# Removes redundent items (like x+-y, 0+x and 1*x, etc) 562# Removes redundent items (like x+-y, 0+x and 1*x, etc)
558# (substituting the given values). 563# using the provided flags
559# 564#
560sub reduce { 565sub reduce {
561 my $self = shift; 566 my $self = shift;
562 $self = $self->copy($self); 567 $self = $self->copy($self);
563 $self->setValues(@_); 568 my $reduce = $self->{context}{reduction};
569 $self->{context}{reduction} = {%{$reduce},@_};
564 $self->{tree} = $self->{tree}->reduce; 570 $self->{tree} = $self->{tree}->reduce;
565 $self->{variables} = $self->{tree}->getVariables; 571 $self->{variables} = $self->{tree}->getVariables;
572 $self->{context}{reduction} = $reduce if $reduce;
566 return $self; 573 return $self;
567} 574}
568 575
569################################################## 576##################################################
570# 577#
690# 697#
691# To Do: 698# To Do:
692# 699#
693# handle sqrt(-1) and log of negatives (make complexes) 700# handle sqrt(-1) and log of negatives (make complexes)
694# do division by zero and log of zero checks in compound functions 701# do division by zero and log of zero checks in compound functions
695# add context flags for various reduction checks
696# make context flag for reduction of constants
697# make reduce have reduce patterns as parameters 702# make reduce have reduce patterns as parameters
698# more reduce patterns 703# more reduce patterns
699# make operator strings customizable (reduce, and other places they are used) 704# make operator strings customizable (reduce, and other places they are used)
700# add parens alternately as () and []?
701# 705#
702######################################################################### 706#########################################################################
703 707
7041; 7081;
705 709

Legend:
Removed from v.2682  
changed lines
  Added in v.2796

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9