| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # OpperationDB.pm - A db of basic opperands and there properties | ||||||||||||||||||||||||||||
| 4 | # (c) Copyright 1998 Hakan Ardo <hakan@debian.org> | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 8 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||
| 9 | # any later version. | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 17 | # along with this program; if not, write to the Free Software | ||||||||||||||||||||||||||||
| 18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Math::Expr::OpperationDB - A db of basic opperands properties | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | require Math::Expr::OpperationDB; | ||||||||||||||||||||||||||||
| 27 | $db=new Math::Expr::OpperationDB($file); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | This is a database containing info about the different opperations | ||||||||||||||||||||||||||||
| 32 | (eg +, -, *, ...). Each opperation is represented by a regexp | ||||||||||||||||||||||||||||
| 33 | mathing a type specifikation. That way Real*Real wont be the same | ||||||||||||||||||||||||||||
| 34 | opperation as Matrix*Matrix even though the same operation character | ||||||||||||||||||||||||||||
| 35 | is used. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | The data stored for each operation is the return type of the | ||||||||||||||||||||||||||||
| 38 | operation and whatever this operation is kommutativ or assosiative. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | Currently the data is hardcoded into the code, but that is about to | ||||||||||||||||||||||||||||
| 41 | chnage. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head1 METHODS | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | package Math::Expr::OpperationDB; | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use Math::Expr; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head2 $db=new Math::Expr::OpperationDB; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Creates a new db. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 1 | my $self = bless {}, shift; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | $self->Load(shift); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | $self; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub InitDB { | ||||||||||||||||||||||||||
|
Subroutine
InitDB: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 1 | my $self=shift; | |||||||||||||||||||||||||||
| 68 | 1 | my $a=$self->{'opps'}; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | foreach (keys %{$a}) { | |||||||||||||||||||||||||||
| 71 | 8 | ▶ | if ($a->{$_}->{'simp'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 2 | $a->{$_}->{'simp'}=Parse($a->{$_}->{'simp'}); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 8 | $a->{$_}{'TypeReg'}=qr/^$_$/; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub Load { | ||||||||||||||||||||||||||
|
Subroutine
Load: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 1 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 80 | 1 | my (%t, @o); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | open (F, "<$file"); | |||||||||||||||||||||||||||
| 83 | 1 | ▶ | while (<F>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 52 | ▶ | if (/^([^:]+)\s*:\s*(.*)$/) {$t{lc($1)}=$2;} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 52 | ▶ | if (/^\s*$/ || eof F) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
/^\s*$/ or eof F
MC/DC50%1/2
/^\s*$/ or eof F
/^\s*$/
eof F
Truth table66%2/3
A or B
A= /^\s*$/B= eof F
| |||||||||||||||||||||||||||||
| 86 | 8 | ▶ | if ($t{'type'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 8 | my $t=$t{'type'}; | |||||||||||||||||||||||||||
| 88 | 8 | delete $t{'type'}; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 8 | ▶ | if (defined $t{'prop'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 2 | @o = split(/\s*,\s*/, $t{'prop'}); | |||||||||||||||||||||||||||
| 92 | 2 | foreach (@o) { | |||||||||||||||||||||||||||
| 93 | 4 | $self->{'opps'}{$t}{lc($_)}=1; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 2 | delete $t{'prop'}; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 8 | foreach (keys %t) { | |||||||||||||||||||||||||||
| 99 | 34 | $self->{'opps'}{$t}{$_}=$t{$_}; | |||||||||||||||||||||||||||
| 100 | 34 | delete $t{$_}; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head2 $db->Find($t) | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | Tries all the type regexps in the db on $t and if one matches that | ||||||||||||||||||||||||||||
| 110 | post is returned. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 585 | ▶ | sub Find { | ||||||||||||||||||||||||||
|
Subroutine
Find: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 585 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 116 | 585 | my $opp; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 585 | foreach (values %{$self->{'opps'}}) { | |||||||||||||||||||||||||||
| 119 | 3249 | ▶ | if ($str =~ $_->{'TypeReg'}) {$opp=$_; last;} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 585 | $opp; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub Keys { | ||||||||||||||||||||||||||
|
Subroutine
Keys: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | keys %{$self->{'opps'}}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub Get { | ||||||||||||||||||||||||||
|
Subroutine
Get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 0 | my ($self, $a) = @_; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | $self->{'opps'}{$a}; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | 1; | |||||||||||||||||||||||||||