{"id":20358577,"url":"https://github.com/selfmadesystem/calculator","last_synced_at":"2025-10-07T00:43:10.015Z","repository":{"id":65807026,"uuid":"600332349","full_name":"SelfMadeSystem/calculator","owner":"SelfMadeSystem","description":"Calculator made in rust","archived":false,"fork":false,"pushed_at":"2023-02-12T06:54:29.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-15T01:46:10.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/SelfMadeSystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-02-11T06:39:16.000Z","updated_at":"2024-05-21T01:04:41.000Z","dependencies_parsed_at":"2023-07-08T22:45:51.263Z","dependency_job_id":null,"html_url":"https://github.com/SelfMadeSystem/calculator","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/SelfMadeSystem%2Fcalculator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SelfMadeSystem%2Fcalculator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SelfMadeSystem%2Fcalculator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SelfMadeSystem%2Fcalculator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SelfMadeSystem","download_url":"https://codeload.github.com/SelfMadeSystem/calculator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241895430,"owners_count":20038512,"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":[],"created_at":"2024-11-14T23:27:37.282Z","updated_at":"2025-10-07T00:43:04.975Z","avatar_url":"https://github.com/SelfMadeSystem.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# calculator\n\nA simple calculator written in Rust.\n\n## Usage\n\n```bash\ncargo run\n```\n\nFor now, you can edit the `main.rs` file to change the expression.\n\n## Features\n\n- [ ] Basic arithmetic\n  - [x] Basic operators (left value, operator, right value) (ex: `2 + 2` or `8 nPr 3`)\n  - [x] Parentheses\n  - [x] Order of operations (PEMDAS)\n  - [ ] Implicit multiplication (ex: `2(2+2)` or `2sqrt(2)`) (will probably do after I dry up the code)\n  - [x] Negative numbers\n- [x] Functions (either before or after a value) (ex: `sqrt 4`, or `4!`)\n- [x] Constants\n  - [x] pi\n  - [x] e\n- [ ] CLI\n  - [ ] Read from stdin (might never happen)\n  - [ ] Read from file (might never happen)\n  - [x] Read from command line (was easier than I thought)\n\n## Algorithm\n\nI made my own algorithm to parse the expression. It's not perfect, but it works.\n\nBasically, after I tokenize (which is pretty easy), I parse the tokens into an\nAST (Abstract Syntax Tree).\n\nThe parser is in `src/parser.rs`. It has essentially two interesting functions:\n`find_and_replace` and `replace_paren`.\n\n`find_and_replace` acts as such:\n1. If num op num found or fun with after as false and num found\n1.1. If next is an operator of strictly higher priority than op or fun or function with strictly higher priority and after is true\n     call find_and_replace at second num's index\n1.2. Else\n     Replace the tokens with ParsedToken\n2. If num and fun with after as true found\n2.1 Replace the tokens with ParsedToken\n\nnum can be either a number, a lparen, or a ParsedToken. If it's an lparen, call replace_paren with position of lparen\n\n`replace_paren` acts as such:\n1. Make subvec from at+1 to the next rparen of same depth\n2. Call find_and_replace on subvec until its length is 1\n3. Replace everything from at to the next rparen with the ParsedToken which is the only element in the subvec\n\nPliz rate. I'm not sure if this is the best way to do it, but it works. I didn't\nwant to dig through a bunch of random articles on the internet to find a\npre-existing algorithm, so I made my own.\n\n## License\n\n[Apache-2.0](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselfmadesystem%2Fcalculator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselfmadesystem%2Fcalculator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselfmadesystem%2Fcalculator/lists"}