{"id":21536603,"url":"https://github.com/abdnh/math-eval","last_synced_at":"2025-03-17T20:26:58.739Z","repository":{"id":105872047,"uuid":"392122645","full_name":"abdnh/math-eval","owner":"abdnh","description":"Math expression evaluator","archived":false,"fork":false,"pushed_at":"2021-08-22T23:28:10.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-24T07:29:49.224Z","etag":null,"topics":["algorithm","math","math-evaluator","math-expression-evaluator","mathematics"],"latest_commit_sha":null,"homepage":"","language":"C","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/abdnh.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":"2021-08-02T23:23:19.000Z","updated_at":"2021-08-22T23:28:12.000Z","dependencies_parsed_at":"2023-04-22T13:04:37.873Z","dependency_job_id":null,"html_url":"https://github.com/abdnh/math-eval","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdnh%2Fmath-eval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdnh%2Fmath-eval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdnh%2Fmath-eval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdnh%2Fmath-eval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abdnh","download_url":"https://codeload.github.com/abdnh/math-eval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244104726,"owners_count":20398727,"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":["algorithm","math","math-evaluator","math-expression-evaluator","mathematics"],"created_at":"2024-11-24T03:20:21.951Z","updated_at":"2025-03-17T20:26:58.734Z","avatar_url":"https://github.com/abdnh.png","language":"C","readme":"# Math Expression Evaluator\n\nThis is just a math expression evaluator in C that I wrote for fun and learning.\nIf you want a production-quality library, take a look at [TinyExpr](https://github.com/codeplea/tinyexpr).\n\n## Description\n\nThe [Shunting-yard algorithm](https://en.wikipedia.org/wiki/Shunting-yard_algorithm) is used for parsing\nexpressions written in [Infix notation](https://en.wikipedia.org/wiki/Infix_notation) (e.g. `5 + 3`).\nMy implementation parses operators and operands and store each type in a separate stack (`ops_stack` and `operands_stack`)\nfor ease of computation, and doesn't provide a function to\nproduce an expression in [Reverse Polish notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation) yet.\n\n## How to use\n\nTo use as a library, copy the necessary sources (all but demo.c, debug.*, tests.c) to your project\nand include `evaluate.h`.\nSee [evaluate.h](evaluate.h) for some docs and [demo.c](demo.c) for a usage example.\n\n## Repo structure\n\n- [demo.c](demo.c) a simple calculator built using the library.\n- [evaluate.c](evaluate.c) uses the [Shunting-yard algorithm](https://en.wikipedia.org/wiki/Shunting-yard_algorithm)\nto evaluate expressions written in [infix notation](https://en.wikipedia.org/wiki/Infix_notation).\n- [ops.c](ops.c) defines the supported operations.\n- [stack.h](stack.h) is a stack implementation to support the algorithm. It's based on the [vector.h](vector.h) file, which\n  I originally wrote for use in my C utilities, so it's generic (i.e macro hell).\n- [debug.c](debug.c) prints some debugging info when the `EVAL_DEBUG` macro is defined.\n- [tests.c](tests.c): some tests\n\n## Building\n\nTo build and run the demo, run:\n```\nmake demo\n```\n\nTo run tests:\n\n```\nmake tests\n```\n\n## TODO\n- More operations and constants\n- Explore more algorithms for mathematical expression parsing\n- Rust version\n- Use an arbitrary-precision arithmetic library to save myself from headaches\n- [Operator associativity](https://en.wikipedia.org/wiki/Operator_associativity). Currently, the exponentiation operator (^) is special-cased to be right-associative.\n  If I'll ever add more right-associative operators, I should modify the `operator` struct to store associativity and remove the special case.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdnh%2Fmath-eval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabdnh%2Fmath-eval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdnh%2Fmath-eval/lists"}