{"id":16130195,"url":"https://github.com/lambdacasserole/sugarsnap","last_synced_at":"2025-04-06T14:14:52.576Z","repository":{"id":75386009,"uuid":"231075085","full_name":"lambdacasserole/sugarsnap","owner":"lambdacasserole","description":"Super generic and reusable shunting and parsing library.","archived":false,"fork":false,"pushed_at":"2020-01-18T00:07:53.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T20:17:21.771Z","etag":null,"topics":["dijkstra","expression","infix-notation","parser","reverse-polish-notation","shunting-yard-algorithm"],"latest_commit_sha":null,"homepage":null,"language":"Java","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/lambdacasserole.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":"2019-12-31T11:01:46.000Z","updated_at":"2020-01-18T00:07:55.000Z","dependencies_parsed_at":"2023-06-06T09:00:13.147Z","dependency_job_id":null,"html_url":"https://github.com/lambdacasserole/sugarsnap","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/lambdacasserole%2Fsugarsnap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdacasserole%2Fsugarsnap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdacasserole%2Fsugarsnap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdacasserole%2Fsugarsnap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lambdacasserole","download_url":"https://codeload.github.com/lambdacasserole/sugarsnap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492543,"owners_count":20947545,"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":["dijkstra","expression","infix-notation","parser","reverse-polish-notation","shunting-yard-algorithm"],"created_at":"2024-10-09T22:14:57.693Z","updated_at":"2025-04-06T14:14:52.552Z","avatar_url":"https://github.com/lambdacasserole.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sugarsnap\nSuper generic and reusable shunting and parsing library.\n\n![Logo](assets/logo-text-h.svg)\n\n## Overview\nThis library implements Dijkstra's [Shunting-yard algorithm](https://en.wikipedia.org/wiki/Shunting-yard_algorithm) in Java, with generics to permit the type-safe attachment of arbitrary objects to symbols.\n\nThe algorithm functions to convert mathematical expressions written in [infix notation](https://en.wikipedia.org/wiki/Infix_notation) to [reverse Polish notation (RPN)](https://en.wikipedia.org/wiki/Reverse_Polish_notation) for easy evaluation using a stack machine. Sugarsnap currenty supports:\n* Functions\n* Operator precedence\n* Left/right operator associativity\n* Parenthesised expressions\n\nThere is currently no support for:\n* Function composition\n* Variadic functions\n* Postfix unary operators (e.g. factorial \"!\")\n\nMismatched brackets etc. will throw exceptions, which can be caught and handled.\n\n## Usage\nThe purpose of this library is to convert infix notation to RPN. That is to say, it does not contain a tokeniser. Once you've wrangled your string into a list of tokens, here's a quick demonstration of what you need to do:\n\n```java\n// Expression: 3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3\n// Expression given as list of symbols with strings attached.\nList\u003cShuntingYardSymbol\u003cString\u003e\u003e input = new LinkedList\u003cShuntingYardSymbol\u003cString\u003e\u003e(Arrays.asList(\n        new ShuntingYardNumber\u003cString\u003e(\"3\"), // A number.\n        // An operator, with precedence 2 and left associativity.\n        new ShuntingYardOperator\u003cString\u003e(\"+\", 2, true),\n        new ShuntingYardNumber\u003cString\u003e(\"4\"),\n        new ShuntingYardOperator\u003cString\u003e(\"*\", 3, true),\n        new ShuntingYardNumber\u003cString\u003e(\"2\"),\n        new ShuntingYardOperator\u003cString\u003e(\"/\", 3, true),\n        new ShuntingYardLeftParen\u003cString\u003e(\"(\"), // An opening parenthesis.\n        new ShuntingYardNumber\u003cString\u003e(\"1\"),\n        new ShuntingYardOperator\u003cString\u003e(\"-\", 2, true),\n        new ShuntingYardNumber\u003cString\u003e(\"5\"),\n        new ShuntingYardRightParen\u003cString\u003e(\")\"), // A closing parenthesis.\n        // Precedence 4 exponentiation operator with right associativity.\n        new ShuntingYardOperator\u003cString\u003e(\"^\", 4, false), \n        new ShuntingYardNumber\u003cString\u003e(\"2\"),\n        new ShuntingYardOperator\u003cString\u003e(\"^\", 4, false),\n        new ShuntingYardNumber\u003cString\u003e(\"3\")));\n        \n// Parse expression.\nShuntingYardParser\u003cString\u003e parser = new ShuntingYardParser\u003cString\u003e();\ntry {\n    List\u003cShuntingYardSymbol\u003cString\u003e\u003e output = parser.parse(input);\n    // Resulting list looks like this (as a string): \"342*15-23^^/+\"\n    // Do what you need to do with result...\n} catch (ShuntingYardParserException e) {\n    // Exception encountered while parsing expression.\n    e.printStackTrace();\n} \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdacasserole%2Fsugarsnap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flambdacasserole%2Fsugarsnap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdacasserole%2Fsugarsnap/lists"}