KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > vectorJep > VectorJep


1 /* @author rich
2  * Created on 19-Dec-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.vectorJep;
9
10 import org.nfunk.jep.*;
11 import org.lsmp.djep.vectorJep.function.*;
12 import org.lsmp.djep.vectorJep.values.*;
13 import java.util.*;
14
15 /**
16  * An extension of JEP with support for basic vectors and matricies.
17  * Use this class instead of JEP if you wish to use vectors and matricies.
18  *
19  * @author Rich Morris
20  * Created on 19-Dec-2003
21  */

22 public class VectorJep extends JEP {
23
24     
25     public VectorJep() {
26         super();
27         
28 /* Operator.OP_ADD.setPFMC(new MAdd());
29         Operator.OP_SUBTRACT.setPFMC(new MSubtract());
30         Operator.OP_MULTIPLY.setPFMC(new MMultiply());
31         Operator.OP_POWER.setPFMC(new MPower());
32         Operator.OP_UMINUS.setPFMC(new MUMinus());
33         Operator.OP_DOT.setPFMC(new MDot());
34         Operator.OP_CROSS.setPFMC(new ExteriorProduct());
35         Operator.OP_LIST.setPFMC(new VList());
36 */

37         opSet = new VOperatorSet();
38         this.parser.setInitialTokenManagerState(Parser.NO_DOT_IN_IDENTIFIERS);
39     }
40
41     public void addStandardFunctions()
42     {
43         super.addStandardFunctions();
44         super.addFunction("ele",new Ele());
45     }
46
47
48     public VectorJep(JEP j) {
49         super(j);
50     }
51
52     /** Evaluate a node. If the result is a scaler it
53      * will be unwrapped, i.e. it will return a Double and not a Scaler.
54      */

55     public Object JavaDoc evaluate(Node node) throws Exception JavaDoc
56     {
57         Object JavaDoc res = ev.getValue(node,new Vector(),this.getSymbolTable());
58         if(res instanceof Scaler)
59             return ((Scaler) res).getEle(0);
60         else
61             return res;
62     }
63
64     /** Evaluate a node. Does not unwrap scalers. */
65     public Object JavaDoc evaluateRaw(Node node) throws Exception JavaDoc
66     {
67         Object JavaDoc res = ev.getValue(node,new Vector(),this.getSymbolTable());
68         return res;
69     }
70
71 }
72
Popular Tags