Giter VIP home page Giter VIP logo

javaluator's People

Contributors

fathzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

javaluator's Issues

Is it possible to implement a method that returns the custom variables from the input given by the user?

Hi! This library is great. Im having just one requirement, however:

Is it possible to implement a method that returns the custom variables from the input given by the user?

For example, the user inputs:

String input = "(workHours^2 * workers)/100";

And for that given input, the method would return : "workHours", "workers".


I did a method that attempts to do that, it works fine except when the variable name contains a number.
For example:
String input = "workHours1^2 * workers2) / 100";

....
allBrackets = new HashSet<>();
        allBrackets.add("(");
        allBrackets.add(")");
        allBrackets.add("[");
        allBrackets.add("]");
        allBrackets.add("}");
        allBrackets.add("{");

        allOperators = new HashSet<>();
        allOperators.add(LocalizedEvaluator.MULTIPLY.getSymbol());
        allOperators.add(LocalizedEvaluator.MODULO.getSymbol());
        allOperators.add(LocalizedEvaluator.DIVIDE.getSymbol());
        allOperators.add(LocalizedEvaluator.EXPONENT.getSymbol());
        allOperators.add(LocalizedEvaluator.MINUS.getSymbol());
        allOperators.add(LocalizedEvaluator.NEGATE.getSymbol());
        allOperators.add(LocalizedEvaluator.NEGATE_HIGH.getSymbol());
        allOperators.add(LocalizedEvaluator.PLUS.getSymbol());

        allFunctions = new HashMap<>();
        allFunctions.put(LocalizedEvaluator.RAIZ, LocalizedEvaluator.RAIZ.getName());
        allFunctions.put(LocalizedEvaluator.ABS, LocalizedEvaluator.ABS.getName());
        allFunctions.put(LocalizedEvaluator.ACOSINE, LocalizedEvaluator.ACOSINE.getName());
        allFunctions.put(LocalizedEvaluator.ASINE, LocalizedEvaluator.ASINE.getName());
        allFunctions.put(LocalizedEvaluator.ATAN, LocalizedEvaluator.ATAN.getName());
        allFunctions.put(LocalizedEvaluator.AVERAGE, LocalizedEvaluator.AVERAGE.getName());
        allFunctions.put(LocalizedEvaluator.CEIL, LocalizedEvaluator.CEIL.getName());
        allFunctions.put(LocalizedEvaluator.COSINE, LocalizedEvaluator.COSINE.getName());
        allFunctions.put(LocalizedEvaluator.COSINEH, LocalizedEvaluator.COSINEH.getName());
        allFunctions.put(LocalizedEvaluator.FLOOR, LocalizedEvaluator.FLOOR.getName());
        allFunctions.put(LocalizedEvaluator.LN, LocalizedEvaluator.LN.getName());
        allFunctions.put(LocalizedEvaluator.LOG, LocalizedEvaluator.LOG.getName());
        allFunctions.put(LocalizedEvaluator.MAX, LocalizedEvaluator.MAX.getName());
        allFunctions.put(LocalizedEvaluator.MIN, LocalizedEvaluator.MIN.getName());
        allFunctions.put(LocalizedEvaluator.TANGENTH, LocalizedEvaluator.TANGENTH.getName());
        allFunctions.put(LocalizedEvaluator.TANGENT, LocalizedEvaluator.TANGENT.getName());
        allFunctions.put(LocalizedEvaluator.SUM, LocalizedEvaluator.SUM.getName());
        allFunctions.put(LocalizedEvaluator.SINEH, LocalizedEvaluator.SINEH.getName());
        allFunctions.put(LocalizedEvaluator.SINE, LocalizedEvaluator.SINE.getName());
        allFunctions.put(LocalizedEvaluator.ROUND, LocalizedEvaluator.ROUND.getName());
        allFunctions.put(LocalizedEvaluator.RANDOM, LocalizedEvaluator.RANDOM.getName());

....


public static ArrayList<String> getVariables(String input) {

        for (String operator : allOperators) {
            input = input.replace(operator.trim(), "");
        }

        for (Map.Entry<Function, String> entry : allFunctions.entrySet()) {
            String translated = entry.getValue();
            input = myReplace(input, translated, "");
        }

        for (String bracket : allBrackets) {
            input = input.replace(bracket.trim(), "");
        }

        input = input.trim();

        String[] words = input.split("\\s+");
        
        ArrayList<String> result = new ArrayList<>();

        for (String word : words) {
            word = word.trim();
            if (!isNumeric(word)) {
                //
                word = word.replaceAll("\\d", "");

                //
                result.add(word);
            }
        }
        
        return result;

    }




Trailing operator evaluates incorrectly

Given an expression with a trailing, right-associative operator, the operator may be evaluated incorrectly.

When using the SimpleBooleanEvaluator, an expression like true! resolves to false, but I believe it should result in a syntax error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.