| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Num.pm - A perl representation of numbers |
|
4
|
|
|
|
|
|
|
# (c) Copyright 1998 Hakan Ardo |
|
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::Num - Represents one number in a parsed expression tree |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
require Math::Expr::Opp; |
|
27
|
|
|
|
|
|
|
require Math::Expr::Var; |
|
28
|
|
|
|
|
|
|
require Math::Expr::Num; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# To represent the expression "x+7": |
|
31
|
|
|
|
|
|
|
$n=new Math::Expr::Opp("+"); |
|
32
|
|
|
|
|
|
|
$n->SetOpp(0,new Math::Expr::Var("x")); |
|
33
|
|
|
|
|
|
|
$n->SetOpp(1,new Math::Expr::Num(7)); |
|
34
|
|
|
|
|
|
|
print $n->tostr . "\n"; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Used by the Math::Expr to represent numbers. |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
package Math::Expr::Num; |
|
45
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
27
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
5
|
use Math::Expr::Node; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
17
|
|
|
48
|
1
|
|
|
1
|
|
4
|
use vars qw(@ISA); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
280
|
|
|
49
|
|
|
|
|
|
|
@ISA = qw(Math::Expr::Node); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 $n=new Math::Expr::Num($num) |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Creates a new representation of the number $num. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub new { |
|
58
|
20
|
|
|
20
|
0
|
37
|
my($class, $val) = @_; |
|
59
|
20
|
|
|
|
|
54
|
my $self = bless { }, $class; |
|
60
|
|
|
|
|
|
|
|
|
61
|
20
|
|
|
|
|
52
|
$self->{'Val'}=$val; |
|
62
|
20
|
|
|
|
|
64
|
$self; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 $n->tostr |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns the string representation of the number which in perl is |
|
68
|
|
|
|
|
|
|
the same as the number itsefle |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
|
71
|
|
|
|
|
|
|
sub tostr { |
|
72
|
292
|
|
|
292
|
1
|
379
|
my $self = shift; |
|
73
|
292
|
|
|
|
|
1278
|
$self->{'Val'}; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
12
|
|
|
12
|
0
|
24
|
sub toText {shift->tostr} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub strtype { |
|
79
|
145
|
|
|
145
|
0
|
340
|
"Real"; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
145
|
|
|
145
|
0
|
340
|
sub BaseType {shift->strtype(@_)} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _toMathML { |
|
85
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
|
86
|
3
|
|
|
|
|
16
|
"".$self->{'Val'}.""; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub SubMatch { |
|
91
|
8
|
|
|
8
|
0
|
11
|
my ($self, $rule, $mset) = @_; |
|
92
|
|
|
|
|
|
|
|
|
93
|
8
|
100
|
66
|
|
|
45
|
if ($rule->isa('Math::Expr::Var') && $self->BaseType eq $rule->BaseType) { |
|
94
|
4
|
|
|
|
|
12
|
$mset->SetAll($rule->{'Val'},$self); |
|
95
|
4
|
|
|
|
|
9
|
return 1; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
4
|
100
|
66
|
|
|
29
|
if ($rule->isa('Math::Expr::Num') && $self->BaseType eq $rule->BaseType) { |
|
98
|
2
|
|
|
|
|
8
|
return 1; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
2
|
|
|
|
|
8
|
return 0; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 $n->Copy |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Returns a new copy of itself. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _Copy { |
|
110
|
6
|
|
|
6
|
|
10
|
my $self= shift; |
|
111
|
|
|
|
|
|
|
|
|
112
|
6
|
|
|
|
|
16
|
new Math::Expr::Num($self->{'Val'}); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Hakan Ardo |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |