{"id":13435818,"url":"https://github.com/kimwalisch/calculator","last_synced_at":"2025-10-03T23:53:49.145Z","repository":{"id":11710982,"uuid":"14228889","full_name":"kimwalisch/calculator","owner":"kimwalisch","description":"C++ operator precedence parser","archived":false,"fork":false,"pushed_at":"2024-03-10T18:11:43.000Z","size":29,"stargazers_count":106,"open_issues_count":0,"forks_count":66,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-06-25T00:04:34.222Z","etag":null,"topics":["c-plus-plus","calculator"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kimwalisch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2013-11-08T09:29:27.000Z","updated_at":"2025-05-11T12:24:08.000Z","dependencies_parsed_at":"2024-10-27T10:53:59.582Z","dependency_job_id":"38a83329-9865-4a70-9459-10fb8e811072","html_url":"https://github.com/kimwalisch/calculator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/kimwalisch/calculator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fcalculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fcalculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fcalculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fcalculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimwalisch","download_url":"https://codeload.github.com/kimwalisch/calculator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fcalculator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278245377,"owners_count":25955014,"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","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c-plus-plus","calculator"],"created_at":"2024-07-31T03:00:39.536Z","updated_at":"2025-10-03T23:53:49.097Z","avatar_url":"https://github.com/kimwalisch.png","language":"C++","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# calculator\n\n```calculator.hpp``` is a header-only C++ library for parsing and\nevaluating integer arithmetic expressions e.g. ```\"10 * (7 - 1)\"```. It compiles with any\nC++ compiler and works with any integer type e.g. ```int```,\n```long```, ```uint64_t```.\n\ncalculator is a simple but fast\n[operator-precedence parser](https://en.wikipedia.org/wiki/Operator-precedence_parser). \n\n# Supported operators\n\n```calculator.hpp``` uses the same operator precedence and associativity\nas the C++ programming language and also supports the power operator.\n\n\u003ctable\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e\u003cb\u003eOperator\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e|\u003c/td\u003e\n    \u003ctd\u003eBitwise Inclusive OR\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e^\u003c/td\u003e\n    \u003ctd\u003eBitwise Exclusive OR\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e\u0026\u003c/td\u003e\n    \u003ctd\u003eBitwise AND\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e~\u003c/td\u003e\n    \u003ctd\u003eUnary Complement \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e\u0026lt;\u0026lt;\u003c/td\u003e\n    \u003ctd\u003eShift Left\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e\u0026gt;\u0026gt;\u003c/td\u003e\n    \u003ctd\u003eShift Right\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e+\u003c/td\u003e\n    \u003ctd\u003eAddition\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e-\u003c/td\u003e\n    \u003ctd\u003eSubtraction\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e*\u003c/td\u003e\n    \u003ctd\u003eMultiplication\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e/\u003c/td\u003e\n    \u003ctd\u003eDivision\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e%\u003c/td\u003e\n    \u003ctd\u003eModulo\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"left\"\u003e\n    \u003ctd\u003e**\u003c/td\u003e\n    \u003ctd\u003eRaise to power\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n# C++ API\n\nFunctions defined in ```calculator.hpp```.\n```C++\nint calculator::eval(const std::string\u0026 expression);\n\ntemplate \u003ctypename T\u003e\nT calculator::eval\u003cT\u003e(const std::string\u0026 expression);\n```\n\n# How to use it\n\n```calculator::eval(\"1+2\")``` takes a string with an integer arithmetic\nexpression as an argument, evaluates the arithmetic expression and returns\nthe result. If the expression string is not a valid integer arithmetic\nexpression a ```calculator::error``` exception is thrown.\n\n```C++\n#include \"calculator.hpp\"\n#include \u003cstdint.h\u003e\n#include \u003ciostream\u003e\n\nint main()\n{\n    try\n    {\n        int result = calculator::eval(\"(0 + ~(255 \u0026 1000)*3) / -2\");\n        std::cout \u003c\u003c result \u003c\u003c std::endl;\n    \n        // 64-bit arithmetic\n        int64_t r64 = calculator::eval\u003cint64_t\u003e(\"2**60\");\n        std::cout \u003c\u003c r64 \u003c\u003c std::endl;\n    }\n    catch (calculator::error\u0026 e)\n    {\n        std::cerr \u003c\u003c e.what() \u003c\u003c std::endl;\n    }\n\n    return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimwalisch%2Fcalculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimwalisch%2Fcalculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimwalisch%2Fcalculator/lists"}