{"id":19147518,"url":"https://github.com/estilles/expression-parser","last_synced_at":"2026-06-18T22:32:00.234Z","repository":{"id":57112075,"uuid":"421607852","full_name":"estilles/expression-parser","owner":"estilles","description":"Tet another infix to postfix/reverse polish notation converter.","archived":false,"fork":false,"pushed_at":"2021-11-09T08:24:35.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T00:42:45.796Z","etag":null,"topics":["infix","infix-to-postfix","parser","postfix","rpn"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/estilles.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":"2021-10-26T22:57:16.000Z","updated_at":"2023-06-29T16:06:22.000Z","dependencies_parsed_at":"2022-08-21T10:31:06.880Z","dependency_job_id":null,"html_url":"https://github.com/estilles/expression-parser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/estilles/expression-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estilles%2Fexpression-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estilles%2Fexpression-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estilles%2Fexpression-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estilles%2Fexpression-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/estilles","download_url":"https://codeload.github.com/estilles/expression-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estilles%2Fexpression-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34510283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"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":["infix","infix-to-postfix","parser","postfix","rpn"],"created_at":"2024-11-09T07:50:36.972Z","updated_at":"2026-06-18T22:32:00.220Z","avatar_url":"https://github.com/estilles.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\" style=\"border-bottom: none;\"\u003eexpression-parser\u003c/h1\u003e\n\u003ch3 align=\"center\"\u003eCustomizable Infix to Postfix Converter/Resolver\u003c/h3\u003e\n\u003chr\u003e\n\u003cdiv align=\"center\"\u003e\u003cimg alt=\"npm (scoped)\" src=\"https://img.shields.io/npm/v/@estilles/expression-parser\"\u003e\u003c/div\u003e\n\n**expression-parser** is yet another infix to postfix/reverse polish notation converter. I created it because I needed the ability to parse expressions with symbols/identifiers/variables of different formats.\n\n## Highlights\n\nSupports the following expression tokens:\n\n- basic binary operators (e.g. +,-,\\*,/,%,^)\n- unary negation operator (e.g. -10)\n- parenthesis for grouping\n\nSupports the following operands:\n\n- Integers (e.g. -10,1,0,1,2,3,...)\n- Floating point numbers (e.g. 3.14159)\n- Symbols in the form if singe upper/lower case letters (e.g. a+b-c)\n- Custom symbom/variable patters (specify your own regular expression)\n\nDetects the following expression errors:\n\n- Too many operands\n- Missing operands\n- Missing opening parenthesis\n- Missing closing parenthesis\n\nIs thoughrouly unit tested.\n\n## Installation\n\n```\nnpm install @estilles/expression-parser\n```\n\n## Usage\n\n### Importing\n\n```JavaScript\nimport { parse, resolve, toString, toArray } from '@estilles/expression-parser'\n```\n\nor\n\n```JavaScript\nconst { parse, resolve, toString, toArray } = require('@estilles/expression-parser')\n```\n\n### API\n\n#### parse()\n\nThe `parse()` function takes a mathematica expression, tokenizes and parses it, then returns a parsed expression object that represents the expression in postfix or reversed polish notation (RPN).\n\nThe resulting postfix/RPN expression can be visualized by converting it to a string using `toString(parsedExpression)` or an array of tokens using `toArray(parsedExpression)` (see below).\n\nThe optional `symbolPattern` is a regular expression used to parse symbols/variables within the expression. The default `symbolPattern` is `/^([a-zA-Z])/`. It will accept single upper or lower case letters. If you want to create your `symbolPattern`, the regular expression must: (a) start with a begin anchor `^`, and (b) capture the name of the symbol/variable in the first capture group.\n\n```JavaScript\nparse(expression : String[, symbolPattern : Regex]) =\u003e parsedExpression\n\ne.g.\nparse('1+2*3/4')\nparse('(a+b)^2*c')\nparse('$(instance:var1) + $(instance:var2)', /^\\$\\(((?:[^:$)]+):(?:[^)$]+))\\)/)\n```\n\n#### toString()\n\nConverts a parsed expression to a string\n\n```JavaScript\ntoString(parsedExpression) =\u003e string\n\ne.g.\ntoString(parse('1+2*3/4')) =\u003e '1 2 3 * 4 / 1 +'\ntoString(parse('(a+b)^2*c')) =\u003e 'a b + 2 ^ c *'\n```\n\n#### toArray()\n\nConverts a parsed expression to an array of tokens\n\n```JavaScript\ntoArray(parsedExpression) =\u003e array\n\ne.g.\ntoString(parse('1+2*3/4')) =\u003e ['1', '2', '3', '*', '4', '/', '1', '+']\ntoString(parse('(a+b)^2*c')) =\u003e ['a', 'b', '+', '2', '^', 'c', '*']\n```\n\n#### resolve(parsedExpression[, values]) -\u003e result\n\nTakes a parsed expression and an optional dictionary of symbol -\u003e values, evaluates the expression and returns the result.\n\n```JavaScript\nresolve(parsedExpression[, values]) =\u003e result\n\ne.g.\nresolve(parse('1+2*3/4')) =\u003e 2.5\nresolve(parse('(a+b)^2*c'), { a: 1, b: 2, c: 3}) =\u003e 27\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festilles%2Fexpression-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Festilles%2Fexpression-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festilles%2Fexpression-parser/lists"}