{"id":18305037,"url":"https://github.com/lfkdsk/just-evaluator","last_synced_at":"2025-07-30T16:34:12.839Z","repository":{"id":94082187,"uuid":"97465743","full_name":"lfkdsk/Just-Evaluator","owner":"lfkdsk","description":"JVM platform, high performance, lightweight expression computing engine, providing interpretation and compilation and other methods to achieve.","archived":false,"fork":false,"pushed_at":"2018-04-17T12:38:11.000Z","size":1306,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T16:54:44.804Z","etag":null,"topics":["express-parser","expression-evaluator","expression-parser","expression-template"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lfkdsk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-17T10:47:00.000Z","updated_at":"2025-02-13T06:51:04.000Z","dependencies_parsed_at":"2023-07-30T09:02:05.804Z","dependency_job_id":null,"html_url":"https://github.com/lfkdsk/Just-Evaluator","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2FJust-Evaluator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2FJust-Evaluator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2FJust-Evaluator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2FJust-Evaluator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfkdsk","download_url":"https://codeload.github.com/lfkdsk/Just-Evaluator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247366695,"owners_count":20927565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express-parser","expression-evaluator","expression-parser","expression-template"],"created_at":"2024-11-05T15:32:15.340Z","updated_at":"2025-04-05T16:32:25.827Z","avatar_url":"https://github.com/lfkdsk.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Just-Evaluator\n\n**JVM platform, high performance, lightweight** expression computing engine, providing interpretation and compilation and other methods to achieve.  \n![](https://travis-ci.org/lfkdsk/Just-Evaluator.svg?branch=Just-Evaluator-20171127061533)\n\n### Usage\n\n#### 1.Eval Simple Expr：\n\n``` java\nJustEL.runEval(\"i * pi + (d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99 ==i * pi +(d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99\", \n        new JustMapContext() {{\n            put(\"i\", 100);\n            put(\"pi\", 3.14d);\n            put(\"d\", -3.9);\n            put(\"b\", (byte) 4);\n            put(\"bool\", false);\n        }};\n```\n\nThen you can get the result from the return value.\n\n#### 2.Eval Simple Expr With Expression:\n\n``` java\nExpression expr = \nJustEL.runEval(\"i * pi + (d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99 ==i * pi + (d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99\");\nexpr.eval(new JustMapContext() {{\n            put(\"i\", 100);\n            put(\"pi\", 3.14d);\n            put(\"d\", -3.9);\n            put(\"b\", (byte) 4);\n            put(\"bool\", false);\n        });               \n```\n\nIn this way, you can build **AST of this expr** at once time, then eval by multi-contexts **many-times**. \n\n#### 3. Compile Expr to Expression \n\n``` java\nExpression expr = \n  JustEL.runCompile(\"i * pi + (d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99 ==i * pi +(d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99\", context);\nexpr.eval(context);\n```\n\nYour Expr String will be compile at **Runtime**, so you can calculate the result of the expr by **Java**. This way  has better permance when you will evaluate the result **million times, or even hundreds of millions of times** with same or different context.\n\n### High-Level Usage\n\n#### 4.Build The Components of  Evaluator By yourself \n\n``` java\n                JustEL.builder()\n                        .lexer(new JustLexerImpl())\n                        .parser(new JustParserImpl())\n                        .compiler(new JustCompilerImpl())\n                        .generator(new JavaCodeGenerator())\n                        .create()\n                        .compile(\"1111 + lfkdsk + sss\", context)\n                        .eval(context)\n```\n\nYou can change all **primary components**  of the Evaluator , contains *lexer* ,  *parser*,  *compiler*,  *template generator* .\n\n#### 5. Extend Function\n\n``` java\n    public static class Add extends ExtendFunctionExpr {\n        @Override\n        public String funcName() {\n            return \"add\";\n        }\n\n        @Override\n        public Object call(Object... params) {\n            Integer left = (Integer) params[0];\n            Integer right = (Integer) params[1];\n\n            if (left != null \u0026\u0026 right != null) {\n                return left + right;\n            }\n\n            return this.call(params);\n        }\n    }\n```\n\nCreate a new class **extend** ExtendFunctionExpr Class，Override funcName and call method，then you can put it into the context and use like this ：\n\n``` java\nJustContext context = new JustContext();\ncontext.putExtendFunc(\"add\", new ExtendFunctionExpr());\nJustEL.runEval(\"add(111, 222.0)\",context);\nJustEL.runCompile(\"add(111, 222.0)\",context);\n```\n\n#### 6. Add Binary Operator Support \n\nJust-Evaluator support **ast-level Binary-Operators** , Extent Operator will be supported as system-operators. \n\n``` java\n    public static class NewOperator extends OperatorExpr {\n\n        public NewOperator(List\u003cAstNode\u003e children) {\n            super(children, 1000);\n        }\n\n\n        @Override\n        public Object eval(JustContext env) {\n            Object left = leftChild().eval(env);\n            Object right = rightChild().eval(env);\n\n            if (isNumber(left) \u0026\u0026 isNumber(right)) {\n                return NumberUtils.computePlusValue(\n                        (Number) NumberUtils.computePlusValue((Number) left, ((Number) right)),\n                        (Number) right);\n            }\n\n            return super.eval(env);\n        }\n\n        @Override\n        public String compile(JustContext env) {\n            StringBuilder builder = new StringBuilder();\n            String left = leftChild().compile(env);\n            String right = rightChild().compile(env);\n            builder.append(\"(\")\n                    .append(left)\n                    .append(\"+\")\n                    .append(right)\n                    .append(\"+\")\n                    .append(right)\n                    .append(\")\");\n\n            return builder.toString();\n        }\n\n        @Override\n        public String funcName() {\n            return \"**\";\n        }\n    }\n\n```\n\nCreate new class **extend** OperatorsExpr Class and override eval or compile method according to your need. \n\nThen you have to set some *symbol support* :\n\n``` java\n// let lexer know ** is Operator-Symbol\nlexer.insertSymbol(\"**\");\n// let parser know symbol, priority, combination and this class.\nparser.insertOperators(\"**\", 2, LEFT, NewOperator.class);\n```\n\n### Performance\n\nPerformance test compared to the other four mainstream expression calculation engine, the time is **100 million times** the pressure test of the contrast time, time unit **in milliseconds**.\n\n#### 1.Pure Const Expr Test\n\nTest usage :\n\n``` java\n1000+100.0*99-(600-3*15)%(((68-9)-3)*2-100)+10000%7*71\n```\n\n![const](art/const.png)\n\n#### 2.Simple Expr Test\n\nTest usage :\n\n``` java\nf+1000+100.0*99-(600-3*15)%(((68-9)-3)*2-100)+10000%7*71+f\n```\n\n![simple](art/simple.png)\n\n#### 3.Complex Expr Test\n\nTest usage:\n\n![complex-test](art/complex.png)\n\nResult：\n\n![complex](art/complex-result.png)\n\nQLExpress and JEXL's results cannot be drawn in the picture. QLExpress use 285000000 ms in the test, and JEXL use 27150000 ms in this test.\n\n### Feature\n\n- [x] Const Folding\n- [x] ​Sub-AST Spliting\n- [x] AstNode \u003c==\u003e Expression\n- [ ] Balance AST Design\n- [ ] ByteCode Support \n\n### Feedback    \nPlease send your feedback as long as there occurs any inconvenience or problem. You can contact me with:\n* Email: lfk_dsk@hotmail.com  \n* Weibo: [@亦狂亦侠_亦温文](http://www.weibo.com/u/2443510260)  \n* Blog:  [刘丰恺](http://lfkdsk.github.io)  \n\n### License\n\n    Copyright 2017 [刘丰恺](http://lfkdsk.github.io/)\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n    \n       http://www.apache.org/licenses/LICENSE-2.0\n    \n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfkdsk%2Fjust-evaluator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfkdsk%2Fjust-evaluator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfkdsk%2Fjust-evaluator/lists"}