{"id":20633552,"url":"https://github.com/davidelettieri/polynomials-pratt-algorithm","last_synced_at":"2025-07-23T20:04:00.158Z","repository":{"id":83965654,"uuid":"309109538","full_name":"davidelettieri/polynomials-pratt-algorithm","owner":"davidelettieri","description":"Parsing polynomials using pratt algorithm","archived":false,"fork":false,"pushed_at":"2021-11-12T07:44:28.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T03:56:31.229Z","etag":null,"topics":["csharp","polynomials","pratt-parser"],"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/davidelettieri.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":"2020-11-01T14:07:14.000Z","updated_at":"2021-11-12T07:44:31.000Z","dependencies_parsed_at":"2023-03-02T18:15:43.830Z","dependency_job_id":null,"html_url":"https://github.com/davidelettieri/polynomials-pratt-algorithm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/davidelettieri/polynomials-pratt-algorithm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidelettieri%2Fpolynomials-pratt-algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidelettieri%2Fpolynomials-pratt-algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidelettieri%2Fpolynomials-pratt-algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidelettieri%2Fpolynomials-pratt-algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidelettieri","download_url":"https://codeload.github.com/davidelettieri/polynomials-pratt-algorithm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidelettieri%2Fpolynomials-pratt-algorithm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266738657,"owners_count":23976439,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["csharp","polynomials","pratt-parser"],"created_at":"2024-11-16T14:20:58.585Z","updated_at":"2025-07-23T20:04:00.132Z","avatar_url":"https://github.com/davidelettieri.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# polynomials-pratt-algorithm\nParsing polynomials using pratt algorithm\n![Build and test](https://github.com/davidelettieri/polynomials-pratt-algorithm/workflows/Build%20and%20test/badge.svg)\n\nUsing a Pratt parser I aim to parse expressions like this `x^2+y^2-1, x=1, y=1` and `xy, x=2, y=3`. Parsing mathematical expressions it's not hard but it already contains some interesting behaviour such as associativity between operators `x+y*z` is equal to `x+(y*z)` and not `(x+y)*z`. For no particular reason I decided to put the variable assignments after the polynomial. The expression `x^2+y^2-1, x=1, y=1` is to be interpreted as you would with this pseudo code\n```\nx=1\ny=1\nprint (x*2+y^2+1)\n```\n\nThe Pratt algorithm allows to create a \"general purpose parser\" in which is possible to plug in all the parser rules needed for your language or grammar. In my implementation I decided to build a parsed with fixed parsing rules by adding them into the constructors. But as you can see in the Java example (see references) it's easy to create a generic parser and plug the rules by subclassing it. \n\n## References \n\nI came across the Pratt parsing algorithm while reading https://craftinginterpreters.com/, which is a great resource on interpreters and compilers. From the same author, a java implementation of a Pratt parser http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/.\n\nMore formal resources are the paper from Pratt in which he explains the algorithm for the first time https://dl.acm.org/doi/10.1145/512927.512931 and a thesis which is more approachable http://vandevanter.net/mlvdv/publications/a-formalization-and-proof-o.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidelettieri%2Fpolynomials-pratt-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidelettieri%2Fpolynomials-pratt-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidelettieri%2Fpolynomials-pratt-algorithm/lists"}