{"id":18017848,"url":"https://github.com/zac-garby/mex","last_synced_at":"2025-06-17T08:35:40.205Z","repository":{"id":57638359,"uuid":"110016767","full_name":"zac-garby/mex","owner":"zac-garby","description":"A maths expression parser/evaluator, in Rust.","archived":false,"fork":false,"pushed_at":"2017-11-11T20:13:39.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T01:39:26.096Z","etag":null,"topics":["evaluator","mathematics","parser","rust","rust-library"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/mex","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zac-garby.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}},"created_at":"2017-11-08T18:50:05.000Z","updated_at":"2017-11-11T20:58:20.000Z","dependencies_parsed_at":"2022-09-16T04:12:16.236Z","dependency_job_id":null,"html_url":"https://github.com/zac-garby/mex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zac-garby/mex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zac-garby%2Fmex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zac-garby%2Fmex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zac-garby%2Fmex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zac-garby%2Fmex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zac-garby","download_url":"https://codeload.github.com/zac-garby/mex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zac-garby%2Fmex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260323169,"owners_count":22991959,"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":["evaluator","mathematics","parser","rust","rust-library"],"created_at":"2024-10-30T04:25:56.333Z","updated_at":"2025-06-17T08:35:40.181Z","avatar_url":"https://github.com/zac-garby.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"_mex_ a parser/evaluator for simple mathematical expressions, with _no_ dependencies at all. Currently, it supports only a _tiny_ amount of syntax. Here are some valid expressions:\n\n```\n\u003e\u003e 10\n10\n\n\u003e\u003e 10 - 3 * 10\n-20\n\n\u003e\u003e π = 3.1415926536\n3.1415926536\n\n\u003e\u003e 5 * π\n15.707963268\n```\n\nAnd that's it, for now.\n\nIt supports the following operators: `+`, `-`, `*`, `/`, `=`.\n\nBut it's easy to add more (by editing the source).\n\nThe crate can be used as a binary or a library. The binary is a REPL, where you enter single expressions line by line and get the result given back to you. An example of the library is below:\n\n```rust\nuse mex::parser;\nuse mex::evaluator;\nuse mex::evaluator::context;\nuse mex::evaluator::object;\n\nfn main() {\n    let input = \"2 * x\";\n    let mut parse = parser::Parser::new(input);\n\n    let mut context = context::Context::new();\n    context.set(\u0026String::from(\"x\"), object::Object::Number(13.5));\n\n    match parse.parse() {\n        Ok(node) =\u003e {\n            match evaluator::eval_node_in(node, \u0026mut context) {\n                Ok(result) =\u003e println!(\"{}\", result),\n                Err(err) =\u003e println!(\"eval error: {:?}\", err),\n            }\n        }\n\n        Err(e) =\u003e println!(\"parse error: {:?}\", e),\n    };\n}\n```\n\nIn the future, I'd like to add these things:\n\n - Simple API for simple uses\n   - e.g. `mex::evaluate(\"1 + 2\")` \u0026rarr; `3`\n\n - Functions\n   - e.g. `f(x, y) = x + y`\n   - e.g. `f(2, 3)` \u0026rarr; `5`\n \n - Customisation / options\n   - Probably via bitflags\n   - Things like which operators are allowed, if you're allowed to define variables, etc...\n\n - Builtins\n   - e.g. `π`, `e`, `sin(θ)`\n   - Going back to the last point: builtins should be optional\n\n - Multiple expressions in one\n   - e.g. `5 + {1, 2, 3}` \u0026rarr; `6`, `7`, and `8`\n   - They would be returned in a hash set, probably\n\n - Symbolic Expressions\n   - e.g. `'x = a + b'` (maybe with different delimiters)\n   - Can be either equations (i.e. with equals), or just simple expressions\n   - `where` clause\n     - e.g. `'a + b' where a = 2, b = 10` \u0026rarr; `12`\n   - `solve ... for`\n     - e.g. `solve 'a = x + b' for x` \u0026rarr; `'x = a - b'`\n     - e.g. `(solve 'a = x + b' for x) where a = 5, b = 2` \u0026rarr; `3`\n     - e.g. `solve 'x^2 + 3x + 2' for x` \u0026rarr; `(x + 1)(x + 2)`\n   - Maybe even integration/differentiation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzac-garby%2Fmex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzac-garby%2Fmex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzac-garby%2Fmex/lists"}