{"id":19584359,"url":"https://github.com/gpalleschi/jevalexpr","last_synced_at":"2026-05-02T05:35:57.614Z","repository":{"id":193277367,"uuid":"648243178","full_name":"gpalleschi/JEvalExpr","owner":"gpalleschi","description":"Extensible Java Library and Tool to parse, interpret, compile and execute commands written in a language SQL Like.","archived":false,"fork":false,"pushed_at":"2023-09-07T13:40:47.000Z","size":360,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T12:42:40.421Z","etag":null,"topics":["compile","compiler","extensible","extensible-parsing","interpreted-language","interpreter","java","language","languages","library","line-command","parse","parser","parser-library"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gpalleschi.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}},"created_at":"2023-06-01T14:17:52.000Z","updated_at":"2023-09-27T08:10:33.000Z","dependencies_parsed_at":"2023-09-07T14:05:36.513Z","dependency_job_id":null,"html_url":"https://github.com/gpalleschi/JEvalExpr","commit_stats":null,"previous_names":["gpalleschi/jevalexpr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gpalleschi/JEvalExpr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpalleschi%2FJEvalExpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpalleschi%2FJEvalExpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpalleschi%2FJEvalExpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpalleschi%2FJEvalExpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpalleschi","download_url":"https://codeload.github.com/gpalleschi/JEvalExpr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpalleschi%2FJEvalExpr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259502565,"owners_count":22867831,"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":["compile","compiler","extensible","extensible-parsing","interpreted-language","interpreter","java","language","languages","library","line-command","parse","parser","parser-library"],"created_at":"2024-11-11T07:47:55.720Z","updated_at":"2026-05-02T05:35:57.572Z","avatar_url":"https://github.com/gpalleschi.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JEvalExpr\n\n\u003c!-- ```\n       _ ______          _ ______                \n      | |  ____|        | |  ____|                \n      | | |____   ____ _| | |__  __  ___ __  _ __ \n  _   | |  __\\ \\ / / _` | |  __| \\ \\/ / '_ \\| '__|\n | |__| | |___\\ V / (_| | | |____ \u003e  \u003c| |_) | |   \n  \\____/|______\\_/ \\__,_|_|______/_/\\_\\ .__/|_|   \n                                      | |         \n                                      |_|         \n``` --\u003e\n\nVery effective Java Library and Tool to parse, compile and execute functions in a language SQL Like. Library is easy estensible with new functions, and it's possible passing a list of variables changing their values between executions.\n\n\u003chr/\u003e\n\n## Table of contents\n\n1. [Overview](#Overview)  \n2. [Compile Function](#Compile-function)  \n3. [Execution Function](#Execution-function)  \n4. [Example](#Example)  \n5. [List Functions](#List-Functions)  \n6. [Line Command Tool](#Lct)  \n6. [Test Tool](#Test-tool)  \n7. [Add New Function](#Addnewfunction)  \n8. [Authors](#Authors)  \n9. [Prerequisites](#Prerequisites)  \n10. [Built With](#Built-With)  \n11. [Licence](#Licence)  \n\n\u003chr/\u003e\n\n\u003ch2 id=\"Overview\"\u003eOverview\u003c/h2\u003e\n\nThe **JEvalExpr** library allows interpret and compile even complex expressions in a language like SQL. It's possible to specify an array of variable names and their type (**Integer, Double, String and Boolean**) during the compilation. \n\nThe compiled expression is simplified into an array of steps it can be executed, if there are variables during execution the array of variable names and relative values ​​must be passed (It is essential that the array has the same order used in compilation stage). Once compiled, the expression can be executed several times and obviously the values ​​of the variables, if present, can be modified between the various executions.  \n\n\u003chr/\u003e\n\n\u003ch2 id=\"Compile-function\"\u003eCompile function\u003c/h2\u003e\n\nTo compile an expression the following steps must be performed :  \n\n1. **Instantiate an object of type Expression** :  \n\n```\n\tpublic Expression(String expr, ArrayList\u003cVariable\u003c?\u003e\u003e var) {\n\t\tsuper();\n\t\tthis.humanExpr = expr;\n\t\tthis.variables = var;\n\t}\n```\n\n\u003e Contructor accept two arguments :  \n\u003e - String  \n\u003e - ArrayList of Variable objects  \n\n\u003e Variable class :  \n\n```\npublic class Variable\u003cT\u003e {\n\tprivate String name;\n\tprivate TypeData typeVariable;\n\t\n\tprivate T value;\n\n\tpublic Variable(String name, T value) {\n\t\tsuper();\n\t\tthis.name = name;\n\t\tif ( Utility.isBoolean(value) ) this.typeVariable = TypeData.E_boolean;\n\t\tif ( Utility.isString(value) ) this.typeVariable = TypeData.E_string;\n\t\tif ( Utility.isInteger(value) ) this.typeVariable = TypeData.E_int;\n\t\tif ( Utility.isDouble(value) ) this.typeVariable = TypeData.E_double;\n\t\tthis.value = value;\n\t}\n\t\n\tpublic T getValue() {\n\t\treturn value;\n\t}\n\t\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic TypeData getTypeVariable() {\n\t\treturn typeVariable;\n\t}\n\n\tpublic void setTypeVariable(TypeData typeVariable) {\n\t\tthis.typeVariable = typeVariable;\n\t}\n\n}\n```\n\n2. **Execute method compExpr() of object Expression** :  \n\n```\npublic boolean compExpr() { ... }\n```\n\u003e This method returns true if compilation is ok or false if nok. All logs are produced in stdout (see. Logger class).   \n\n\u003chr/\u003e\n\n\u003ch2 id=\"Execution-function\"\u003eExecution function\u003c/h2\u003e\n\nTo execute a compiled expression the following steps must be performed :  \n\n1. **Execute method execExpr(...) of object Expression** :\n\n```\npublic int execExpr(ArrayList\u003cVariable\u003c?\u003e\u003e variables) { ... }  \n```\n\n\u003e It's very important that arrayList of variables has the same order and types of data used during compilaling.   \n\u003e This method returns true if compilation is ok or false if nok. All logs are produced in stdout (see. Logger class).   \n\n3. **Execute method getResult(...) of object Expression** :\n\n```\n\tpublic DataValue\u003c?\u003e getResult() {\n\t\tint idx = expBin.getStep().size()-1;\n\t\tif ( idx \u003c 0 ) idx = 0;\n\t\treturn expBin.getStep().get(idx).getData();\n\t}\n```\n\n\u003e This method returns an object DataValue with the result expression's result and its type.  \n\n```\npublic class DataValue\u003cT\u003e {\n\n\tTypeData typeData;\n\tboolean isNull;\n\tT value;\n\t\n\tpublic DataValue() {\n\t\tsuper();\n\t}\n\n\tpublic DataValue(T value) {\n\t\tsuper();\n\t\tthis.value = value;\n\t}\n\t\n\tpublic TypeData getTypeData() {\n\t\treturn typeData;\n\t}\n\tpublic void setTypeData(TypeData typeData) {\n\t\tthis.typeData = typeData;\n\t}\n\tpublic boolean isNull() {\n\t\treturn isNull;\n\t}\n\tpublic void setNull(boolean isNull) {\n\t\tthis.isNull = isNull;\n\t}\n\tpublic T getValue() {\n\t\treturn value;\n\t}\n\tpublic void setValue(T value) {\n\t\tthis.value = value;\n\t}\n\n}\n```\n\n\u003e To get de type of result execute method getTypeData that returns a **TypeData** enum :  \n\n```\npublic enum TypeData {\n\t  E_int,                      /* Type Integer                   */\n\t  E_double,                   /* Type Double                    */\n\t  E_string,                   /* Type String                    */\n\t  E_boolean,                  /* Type Boolean                   */\n\t  E_date,                     /* Type date (LocalDate, LocalDateTime or LocalTime) */\n}\n```\n\n\u003chr/\u003e\n\n\u003ch2 id=\"Example\"\u003eExample\u003c/h2\u003e\n\nHere an example :\n\n```\npackage com.gpsoft.jtestevalexpr;\nimport java.util.ArrayList;\n\nimport com.gpsoft.jevalexpr.Variable;\nimport com.gpsoft.jevalexpr.expr.Expression;\nimport com.gpsoft.jevalexpr.log.Logger;\n\n\npublic class JTestEvalExpr {\n\t\n\tstatic Expression expression = null;\n\t\n\tpublic static void execute(ArrayList\u003cVariable\u003c?\u003e\u003e variables) {\n\t\t  if ( expression.execExpr(variables) != 0 ) {\n\t\t\t  Logger.error(\"\\nDuring execution\");\n\t\t  } else {\n\t\t\t  Logger.info(\"\\nExecution OK.\");\n\t\t\t  Logger.always(\"-----------------------------------------------\");\n\t\t\t  Logger.always(\"Result : \u003e\" + expression.getResult().getValue() + \"\u003c\");\n\t\t\t  Logger.always(\"Type : \" + expression.getResult().getTypeData());\n\t\t\t  Logger.always(\"IsNull : \" + expression.getResult().isNull());\n\t\t  }\n\t}\n\t\n\t@SuppressWarnings(\"unchecked\")\n\tpublic static void main(String args[]) throws Exception {\n\t\t\n\t\t  // Change Level of Log \n\t\t  Logger.setLevel(8);\n\t\t  String Expression = \"\";\n\n\n\t\t  \n\t\t  ArrayList\u003cVariable\u003c?\u003e\u003e variables = new ArrayList\u003cVariable\u003c?\u003e\u003e();\n\t\t  \n\t\t  variables.add(new Variable\u003cString\u003e(\"v1\", \"Hello World!!!\"));\n\t\t  variables.add(new Variable\u003cBoolean\u003e(\"v2\", true));\n\t\t  variables.add(new Variable\u003cDouble\u003e(\"v3\", 1.234567));\n\t\t  variables.add(new Variable\u003cInteger\u003e(\"v4\", 2));\n\t\t  \n\t\t  for(int i=0;i\u003cvariables.size();i++) {\n\t\t     Logger.always(\"v\" + (i + 1) + \" : \" + variables.get(i).getValue());\n\t\t  }\n\t\t  Logger.always(\"\");\n\n\t      Expression = \"((1 + v4) \u003e 2) ? substr(v1,1,6) || upper('world') : lower(substr(v1,6,6))\";\n\t      \n\t      expression = new Expression(Expression,variables);\n\t\t\t\t\t  \n\t\t  if ( !expression.compExpr() ) {\n\t\t\t  Logger.error(\"During Compilation\");\n\t\t  } else {\n\t\t\t  Logger.info(\"Compilation OK.\");\n\t\t\t  \n\t\t\t  Logger.always(\"\\nFirst Execution\");\n\t\t\t  execute(variables);\n\t\t\t  \n\t\t\t  ((Variable\u003cString\u003e)variables.get(0)).setValue(\"12345Bye!!!\");\n\t\t\t  ((Variable\u003cInteger\u003e)variables.get(3)).setValue(1);\n\t\t\t  \n\t\t\t  Logger.always(\"\\nSecond Execution\");\n\t\t\t  execute(variables);\n\t\t  }\n\t}\n}\n```\n\u003e Output : \n\u003cdiv style=\"flex\"\u003e\n\u003cimg src=\"./screenshots/example1.PNG\" alt=\"W-Badge\" style=\"height: 30%; width:100%;\"/\u003e\n\u003c/div\u003e\n\n\u003chr/\u003e\n\n\u003ch2 id=\"List-Functions\"\u003eList Functions\u003c/h2\u003e\n\n[Functions and examples](./src/com/gpsoft/jevalexpr/functions/ListFunctions.md)\n\n\u003chr/\u003e\n\n\n\u003ch2 id=\"Lct\"\u003eLine Command Tool\u003c/h2\u003e\n\nIt's possible test this library with a Line Command Tool from executable class [JEvalExpr](./src/com/gpsoft/jevalexpr/JEvalExpr.java).  \n\nUsing this tool you can insert an expression by line command and execute it, checking the result : \n\n\n\u003cdiv style=\"flex\"\u003e\n\u003cimg src=\"./screenshots/LCtool1.PNG\" alt=\"W-Badge\" style=\"height: 30%; width:100%;\"/\u003e\n\u003c/div\u003e\n\nAfter inserted the expression and pressed enter, you can see the result by stdout.  \n\n\u003cdiv style=\"flex\"\u003e\n\u003cimg src=\"./screenshots/LCtool2.PNG\" alt=\"W-Badge\" style=\"height: 30%; width:100%;\"/\u003e\n\u003c/div\u003e\n\n\u003chr/\u003e\n\n\u003ch2 id=\"Test-tool\"\u003eTest tool\u003c/h2\u003e\n\nIt's possible create and execute massive test using executable class [JEvalExprTest](./src/com/gpsoft/jevalexpr/JEvalExprTest.java).  \n\nActually are loaded more than 170 tests, once executed you can check results on stdout :  \n\n\u003cdiv style=\"flex\"\u003e\n\u003cimg src=\"./screenshots/TestTool1.PNG\" alt=\"W-Badge\" style=\"height: 30%; width:100%;\"/\u003e\n\u003c/div\u003e\n\n\u003chr/\u003e\n\n\u003ch2 id=\"Addnewfunction\"\u003eAdd New Function\u003c/h2\u003e\n\nTo add a new function you have to execute these three steps :  \n\n1. Create a new file function java in functions directory **JEvalExpr\\src\\com\\gpsoft\\jevalexpr\\functions**  \n\n\u003e Syntax is F + function name with uppercase first letter. ( ex. FDecode ).\n\u003e New Function has to extend abstract class [Function](./src/com/gpsoft/jevalexpr/functions/Function.java).\n\u003e It's important implement the Constructor and two methods : Check and Exec.\n\n**Constructor**  \n| Actibute   |      Description      |\n|----------|:-------------:|\n| name |  Function Name |\n| typeToken | [TypeToken](./src/com/gpsoft/jevalexpr/TypeToken.java) |\n| operatorSyntaxType | [OperatorSyntaxType](./src/com/gpsoft/jevalexpr/OperatorSyntaxType.java) |\n| operatorPriority | [OperatorPriority](./src/com/gpsoft/jevalexpr/OperatorPriority.java) |\n| idxPartOpe | Index from 0 to indicate component in composite functions like (between ... and) |\n| valueType | [ValueType](./src/com/gpsoft/jevalexpr/ValueType.java) |\n| stepRef |Set to 0 |\n| typeData | Set to [TypeData](./src/com/gpsoft/jevalexpr/TypeData.java).E_string |\n\n**Check**  \nCheck function checks corrects type of arguments and set return type. Return true if is OK or false if not.  \n```\n\t/**\n\t * This method checks function, number of arguments, types, ...\n\t * \n\t * @param expBin\n\t * @param stepIdx\n\t * @return boolean (true if it's ok false is nok)\n\t */\n\t\n\tpublic boolean check(ExpBin\u003c?\u003e expBin, int stepIdx) {\n\t\treturn false;\n\t}\n```\n**Exec**  \nExec function executes funtion and set result. Return true if is OK or false if not.  \n```\n\t/**\n\t * This method execute function\n\t * \n\t * @param expBin\n\t * @param stepIdx\n\t * @return boolean (true if it's ok false is nok)\n\t */\n\t\n\tpublic boolean exec(ExpBin\u003c?\u003e expBin, int stepIdx) {\n\t\treturn false;\n\t}\n```\n2. Add new Function in HashMap **names** present in class [Functions](./src/com/gpsoft/jevalexpr/functions/Functions.java) :  \n\nExample :  \n\n\u003e put(\"between\", new FBetween_and());\n\nWhere \"between\" is the function reserved word and FBetween_and() is new function created.   \n\n3. Add new enum present in enum [TypeStep](./src/src/com/gpsoft/jevalexpr/TypeStep.java), with prefix E_ .   \n\nExample : \n\n\u003e  E_between_and               /* FUNCTION between_and         */  \n\n\u003chr/\u003e\n\n\u003ch2 id=\"Authors\"\u003eAuthors\u003c/h2\u003e\n\n* **Giovanni Palleschi** - [gpalleschi](https://github.com/gpalleschi)  \n\n\u003chr/\u003e\n\n\u003ch2 id=\"Prerequisites\"\u003ePrerequisites\u003c/h2\u003e\n\n`\u003e= Java 1.7`  \n\n\u003chr/\u003e\n\n\u003ch2 id=\"Built-With\"\u003eBuilt With\u003c/h2\u003e\n\n* [Eclipse 2023-03](https://www.eclipse.org/) \n\n\u003chr/\u003e\n\n\u003ch2 id=\"Licence\"\u003eLicence\u003c/h2\u003e\n\nThis project is licensed under the GNU GENERAL PUBLIC LICENSE 3.0 License - see the [LICENSE](LICENSE) file for details. There are 8 pre loaded variables of different types (String, Boolean, Double and Integer).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpalleschi%2Fjevalexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpalleschi%2Fjevalexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpalleschi%2Fjevalexpr/lists"}