Changeset 202


Ignore:
Timestamp:
08/08/08 11:03:47 (16 years ago)
Author:
ra33
Message:

Fixed problem with Simple CalculateString command

Location:
trunk/src/org/expeditee
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Simple.java

    r190 r202  
    325325        }
    326326
    327         private static void RunFrame(Frame frame, Text current, boolean acceptKeyboardInput,
    328                         boolean step, int pause, Color color) {
     327        private static void RunFrame(Frame frame, Text current,
     328                        boolean acceptKeyboardInput, boolean step, int pause, Color color) {
    329329                try {
    330330                        DisplayIO.addToBack(current.getParent());
     
    354354        }
    355355
    356         public static void RunFrame(Frame frame, Text current, boolean acceptKeyboardInput) {
     356        public static void RunFrame(Frame frame, Text current,
     357                        boolean acceptKeyboardInput) {
    357358                RunFrame(frame, current, acceptKeyboardInput, false, 0, null);
    358359        }
     
    368369         * @param pause
    369370         */
    370         public static void DebugFrame(Frame frame, Text current, float pause, Color color) {
     371        public static void DebugFrame(Frame frame, Text current, float pause,
     372                        Color color) {
    371373                if (isProgramRunning()) {
    372374                        stop();
     
    794796                        // Add the variables in the system
    795797                        context.getPrimitives().addToParser(myParser);
    796                         Node equation = myParser.parseExpression(toCalculate);
    797                         // TODO get the answer
    798                         if (equation == null) {
     798                        try {
     799                                Node equation = myParser.parse(toCalculate);
     800                                String value = myParser.evaluate(equation, false);
     801                                // Add a new variable if its an assignment statement
     802                                String newVar = SReal.prefix + myParser.getNewVariable();
     803                                if (newVar.length() > 0) {
     804                                        try {
     805                                                context.getPrimitives().setValue(newVar,
     806                                                                new SString(value));
     807                                        } catch (IncorrectTypeException e) {
     808                                                result = false;
     809                                                error = e.getMessage();
     810                                        }
     811                                }
     812                                if (tokens.length > 2) {
     813                                        context.getPrimitives().setValue(tokens[2],
     814                                                        new SString(value));
     815                                }
     816                                // TODO get the answer
     817                        } catch (Throwable e) {
    799818                                result = false;
    800                                 error = myParser.getErrorInfo().replace("\n", "");
    801                         } else {
    802                                 double value = myParser.getValue();
    803                                 if (myParser.hasError()) {
    804                                         result = false;
     819                                if (myParser.getErrorInfo() == null) {
     820                                        error = e.getMessage();
     821                                } else {
    805822                                        error = myParser.getErrorInfo().replace("\n", "");
    806                                 } else {
    807                                         // Add a new variable if its an assignment statement
    808                                         String newVar = myParser.getNewVariable();
    809                                         if (newVar.length() > 0) {
    810                                                 try {
    811                                                         context.getPrimitives().setValue(newVar,
    812                                                                         new SReal(value));
    813                                                 } catch (IncorrectTypeException e) {
    814                                                         result = false;
    815                                                         error = e.getMessage();
    816                                                 }
    817                                         }
    818                                         if (tokens.length > 2) {
    819                                                 context.getPrimitives().setValue(tokens[2],
    820                                                                 new SReal(value));
    821                                         }
    822823                                }
    823824                        }
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r199 r202  
    6565         * The title to display in the Title bar.
    6666         */
    67         public static final String TITLE = "Exp07Aug2008A";
     67        public static final String TITLE = "Exp08Aug2008A";
    6868
    6969        private DisplayIO() {
  • trunk/src/org/expeditee/math/ExpediteeJEP.java

    r196 r202  
    5050        }
    5151
    52         public String evaluate(Node node) throws ParseException{
     52        public String evaluate(Node node) throws ParseException {
     53                return evaluate(node, true);
     54        }
     55
     56        public String evaluate(Node node, boolean prependVarName)
     57                        throws ParseException {
    5358                Object rawResult = super.evaluate(node);
    5459                if (rawResult instanceof Double) {
    55                         Double result = (Double)rawResult;
     60                        Double result = (Double) rawResult;
    5661                        if (result.isNaN()) {
    5762                                return null;
     
    6469                        String varName = observer.toString();
    6570                        if (varName.length() > 0)
    66                                 return varName + ": " + nf.format(result);
     71                                return (prependVarName ? (varName + ": ") : "")
     72                                                + nf.format(result);
    6773
    6874                        return nf.format(result);
     
    8894                                                frame, t.getEnclosedShape());
    8995                                String variableName = t.getText().toLowerCase();
    90                                
     96
    9197                                addVectorVariable(enclosed, variableName);
    9298                        }
     
    102108                for (Item i : items) {
    103109                        if (i instanceof Text && !i.isLineEnd()) {
    104                                 Double value = AttributeUtils.getDoubleValue(i
    105                                                 .getText());
     110                                Double value = AttributeUtils.getDoubleValue(i.getText());
    106111                                if (value != null) {
    107112                                        vector.add(value);
     
    110115                }
    111116                if (vector.size() > 0)
    112                         addVariable(variableName, MVector
    113                                         .getInstance(vector.toArray()));
     117                        addVariable(variableName, MVector.getInstance(vector.toArray()));
    114118        }
    115119
  • trunk/src/org/expeditee/simple/Primitives.java

    r190 r202  
    272272                        try {
    273273                                Double value = var.doubleValue();
    274                                 myParser.addVariable(var.getName(), value);
     274                                myParser.addVariable(var.getName().substring(SReal.prefix.length()), value);
    275275                        } catch (Exception e) {
    276276                        }
Note: See TracChangeset for help on using the changeset viewer.