{"id":18325989,"url":"https://github.com/mthaler/arithmetic-expression-parser","last_synced_at":"2025-09-13T00:36:12.651Z","repository":{"id":144529204,"uuid":"324088102","full_name":"mthaler/arithmetic-expression-parser","owner":"mthaler","description":"Simple arithmetic expression parser written in Kotlin","archived":false,"fork":false,"pushed_at":"2023-11-22T11:49:26.000Z","size":161,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T09:44:19.391Z","etag":null,"topics":["arithmetic","arithmetic-expression-parser","kotlin","kotlin-library","parser","parser-combinators","parsers"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/mthaler.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":"2020-12-24T06:51:04.000Z","updated_at":"2023-01-07T11:46:50.000Z","dependencies_parsed_at":"2023-11-22T12:47:16.816Z","dependency_job_id":null,"html_url":"https://github.com/mthaler/arithmetic-expression-parser","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/mthaler%2Farithmetic-expression-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthaler%2Farithmetic-expression-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthaler%2Farithmetic-expression-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthaler%2Farithmetic-expression-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mthaler","download_url":"https://codeload.github.com/mthaler/arithmetic-expression-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248064694,"owners_count":21041862,"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":["arithmetic","arithmetic-expression-parser","kotlin","kotlin-library","parser","parser-combinators","parsers"],"created_at":"2024-11-05T19:05:13.855Z","updated_at":"2025-04-09T15:54:12.685Z","avatar_url":"https://github.com/mthaler.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arithmetic-expression-parser\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.mthaler/aparser/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.mthaler/aparser)\n\n**arithmetic-expression-parser** is a simple arithmetic expression parser written in Kotlin. It supports the following operations:\n\n- unary: -\n- binary: +, -, *, /, ^ (power), % (modulo)\n- functions: abs, acos, asin, atan, cos, cosh, exp, ln, log, sin, sinh, sqrt, tan, tanh\n\nFor trigonometric functions, both radians and degrees are supported.\n\n# Design\n\nThe parser is build using combinators. Parsing is a two-step process:\n\n- the tokens package provides various token parsers that match certain tokens, e.g. char literals, identifiers, numbers etc.\n- arithmetic package defines expression parsers that use the token parsers to create parsers for arithmetic expressions.\n\n# Usage\n\nThe `Expression` object parses arithmetic expressions:\n\n```kotlin\nExpression(\"3 + 4\")\n```\n\nThis will return an abstract syntax tree. The `tryEval` extension method can be used to evaluate the expression:\n\n```kotlin\nExpression(\"3 + 4\").tryEval()\n```\n\nThe result will be `Success(7.0)`. If an invalid expression like `Expression(\"foo(0)\")` is evaluated, a `Failure` will be returned.\n\n## Trigonometric units\n\nThe default trigonometric unit is radians, but degrees are also supported:\n\n```kotlin\nval ctx = Context.Empty.copy(trigonometricUnit = TrigonometricUnit.Degree)\nExpression(\"sin(90)\").tryEval(ctx)\n```\n\nThe result will be `Success(1.0)`.\n\n## Global variables\n\nGlobal variables can be defined using upper case letters:\n\n```kotlin\nval ctx = Context(TrigonometricUnit.Rad, mapOf(Pair(\"A\", 2.0)))\nExpression(\"A + 3\").tryEval(ctx)\n```\n\nThe result will be `Success(5.0)`.\n\n# License\n\nApache-2.0 License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmthaler%2Farithmetic-expression-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmthaler%2Farithmetic-expression-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmthaler%2Farithmetic-expression-parser/lists"}