SCalc
Main Page
Related Pages
Classes
Files
File List
lib
expression.hh
1
/*
2
expression.hh, copyright (c) 2006 by Vincent Fourmond:
3
The main header file for SCalc.
4
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details (in the COPYING file).
14
15
*/
16
17
namespace
SCalc {
18
// I like Javadoc-like comments the best
19
20
class
Expression;
21
class
FuncDef;
22
class
SyntaxError;
23
36
class
ParserResult
{
38
Session
* sess;
39
public
:
41
ParserResult
(
Session
* s) {sess = s;};
42
virtual
~
ParserResult
() {;};
43
48
Session
*
session
() {
return
sess;};
49
50
// A whole set of what am I functions, all returning false
51
// (so that the children don't actually need to redefine anything.
52
53
55
56
57
58
59
60
65
virtual
int
is_expression
() {
return
0;}
66
71
Expression
*
to_expression
() {
72
if
(
is_expression
())
73
return
(
Expression
*)
this
;
74
else
75
return
NULL;
76
};
77
78
83
virtual
int
is_syntax_error
() {
return
0;}
84
89
SyntaxError
*
to_syntax_error
() {
90
if
(
is_syntax_error
())
91
return
(
SyntaxError
*)
this
;
92
else
93
return
NULL;
94
};
95
100
virtual
int
is_func_def
() {
return
0;}
101
106
FuncDef
*
to_func_def
() {
107
if
(
is_func_def
())
108
return
(
FuncDef
*)
this
;
109
else
110
return
NULL;
111
};
112
114
115
117
virtual
std::string
pretty_print
() = 0;
118
121
virtual
int
can_delete
() {
return
1;};
122
};
123
124
131
class
Expression
:
public
ParserResult
{
132
public
:
133
Expression
(
Session
* s) :
ParserResult
(s) {;};
134
virtual
~
Expression
() {;};
135
137
virtual
int
is_expression
() {
return
1;};
138
155
virtual
double
evaluate
(
const
double
* values,
156
const
double
* s = NULL) = 0;
157
163
virtual
void
dump
(::std::ostream & stream = ::std::cerr);
164
170
virtual
std::set<int>
used_variables
() { std::set<int> a;
return
a;};
171
173
int
evaluable
() {
return
session
()->
evaluable
(
this
);};
175
double
evaluate
();
176
179
virtual
int
is_null
() {
return
0;};
180
182
virtual
int
is_id
() {
return
0;};
183
185
virtual
int
is_const
() {
return
0;};
186
189
virtual
int
is_valid
() {
return
1;};
190
204
virtual
Expression
*
derive
(
int
id
);
205
207
virtual
Expression
*
copy
() {
return
NULL;};
208
215
virtual
std::string
pretty_print
() = 0;
216
217
228
virtual
Expression
*
simplify
() {
return
copy
();};
229
242
virtual
double
*
mass_evaluate
(
int
nb,
double
* target,
const
double
**variables);
243
249
251
static
Expression
* add(
Expression
*,
Expression
* );
252
static
Expression
* sub(
Expression
*,
Expression
* );
253
static
Expression
* mul(
Expression
*,
Expression
* );
254
static
Expression
* div(
Expression
*,
Expression
* );
257
};
258
259
260
};
261
Generated by
1.8.1.2