-
Notifications
You must be signed in to change notification settings - Fork 8
/
BBasicExpression.java
65 lines (54 loc) · 1.61 KB
/
BBasicExpression.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Vector;
public class BBasicExpression extends BExpression
{ private String data;
private Vector parameters; // for constants (functions)
// private int umlkind;
public BBasicExpression(String d)
{ data = d; }
public BBasicExpression(String d, Vector pars)
{ data = d;
parameters = pars;
}
// public void setUmlKind(int k)
// { umlkind = k; }
public Vector rd()
{ Vector res = new Vector();
if (kind != Expression.VALUE)
{ res.add(data); } // add all parameters?
return res;
}
public boolean setValued()
{ return false; } // could be
public BExpression simplify()
{ BExpression res = new BBasicExpression(data,parameters);
res.setKind(kind);
return res;
}
public String toString()
{ if (parameters == null)
{ return data; }
else
{ String res = data + "(";
for (int i = 0; i < parameters.size(); i++)
{ res = res + parameters.get(i);
if (i < parameters.size() - 1)
{ res = res + ","; }
}
res = res + ")";
return res;
}
}
public BExpression substituteEq(String oldE, BExpression newE)
{ if (oldE.equals(toString())) { return newE; }
if (parameters != null)
{ Vector newpars = new Vector();
for (int i = 0; i < parameters.size(); i++)
{ BExpression par = (BExpression) parameters.get(i);
BExpression newpar = par.substituteEq(oldE,newE);
newpars.add(newpar);
}
return new BBasicExpression(data,newpars);
}
return this;
}
}