{"id":17231937,"url":"https://github.com/pushfoo/stacalc","last_synced_at":"2025-03-26T00:25:51.712Z","repository":{"id":172468154,"uuid":"649334102","full_name":"pushfoo/Stacalc","owner":"pushfoo","description":"A tiny stack calculator with some Forth words added. Written in C# for .NET 7.0 to refresh my skills.","archived":false,"fork":false,"pushed_at":"2023-06-12T03:32:44.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T21:16:12.678Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/pushfoo.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":"2023-06-04T14:27:39.000Z","updated_at":"2024-05-21T10:22:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b7c3100-ae06-4bd7-9b32-cea19511195a","html_url":"https://github.com/pushfoo/Stacalc","commit_stats":null,"previous_names":["pushfoo/stacalc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushfoo%2FStacalc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushfoo%2FStacalc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushfoo%2FStacalc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pushfoo%2FStacalc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pushfoo","download_url":"https://codeload.github.com/pushfoo/Stacalc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245564283,"owners_count":20636088,"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-10-15T05:00:01.096Z","updated_at":"2025-03-26T00:25:51.680Z","avatar_url":"https://github.com/pushfoo.png","language":"C#","readme":"# Stacalc\n\nA tiny stack calculator with some\n[Forth](https://en.wikipedia.org/wiki/Forth_(programming_language))\nwords added for convenience. Written in C# for .NET 7.0 to refresh my skills.\nIf you already know what a stack calculator is, skip to the usage section\nbelow.\n\nFor the really impatient:\n1. Clone this repo\n2. Run `dotnet run` in your terminal with the [.NET 7.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) installed\n3. Enter something like `3 2 +` and press enter.\n\nThe supported math operators include `+`, `-`, `*`, and `/`. A full list of\nsupported words is located at the end of this file.\n\n## What's a Stack Calculator \u0026 Why?\n\n### tl;dr\n\n1. I want to focus on learning C# without adding a second complicated grammar\n2. Postfix is easier and less ambiguous than other syntax\n3. It's a step towards building a concatenative language\n\n### Postfix: Math, but not as most know it.\n\nThe usual way of writing arithmetic is called infix notation. It puts operators\nlike `+` between two operands. Postfix notation puts them afterward. For\nexample:\n\n| Infix (normal)      | Postfix         |\n| ------------------- | --------------- |\n| `1 + 2`             | `1 2 +`         |\n| `(8 - 2) * 3`       | `8 2 - 3 *`     |\n| `(9 - 1) / (1 + 3)` | `9 1 - 1 3 + /` |\n\nPostfix doesn't use parentheses because it doesn't need them. The order of\noperations always happens in the order they appear: from left to right.\n\n### Stacks?\n\nSince the order of operations is always clear, we can treat the numbers as\na stack. Entering a number puts it on top, and a math operation will take two numbers and put back one.\n\nFor example, let's look at how `8 2 - 3 *` is executed.\n\n1. `8` is pushed onto the stack\n2. `2` is pushed onto the stack\n2. `-` removes the top two elements and puts `6` on top of the stack\n4. `3` is pushed onto the stack\n5. `*` removes the top two elements and puts `18` on top of the stack\n\n### Next Steps\n\nWith stacks, we can reorder our expressions to put the operators at the end.\n\n1. `3` is pushed onto the stack\n1. `8` is pushed onto the stack\n2. `2` is pushed onto the stack\n2. `-` removes the top two elements and puts `6` on top of the stack\n5. `*` removes the top two elements and puts `18` on top of the stack\n\nAs long as each operator has enough operands on the stack, it doesn't matter\nhow far after the numbers it is. If we add some new stack reordering words,\nwe can begin separating our data from our code to define functions. This is\nan important step toward user-defined words and turning a calculator into\na programming language.\n\n## Usage\n\n### Requirements\n\n* The [.NET 7.0 C# SDK](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)\n* The ability to open \u0026 run commands in the terminal\n\n### Building \u0026 Launching\n\nOnce you have the .NET 7.0 SDK installed, you can launch from the root directory as follows:\n```console\n$ dotnet run\nStacalc: a tiny stack calculator in C#\nUse the exit command to quit the program\n\u003e\n```\n\n### Usage Example\n\nLike a Forth, Stacalc treats input as one of two things:\n\n* Signed 32-bit integers in decimal format\n* Words, which are commands to do something such as add or exit\n\n```console\n$ dotnet run\nStacalc: A tiny stack calculator in C#\nUse the exit command to quit the program\n\u003e 9 5 -2\n9 5 -2\n\u003e +\n9 3\n\u003e /\n3\n\u003e exit\n```\n\n### Supported Words\n\nA word is anything other than a number literal. These include mathematical operators as\nwell as stack manipulation.\n\n| Word | Minimum Stack Size | Action                                               |\n|------|--------------------|------------------------------------------------------|\n|`exit`| 0                  | Exit the program.                                    |\n|`dup` | 1                  | Push a copy of the top element onto the stack        |\n|`drop`| 1                  | Pop an element off the stack and throw it away       |\n|`swap`| 2                  | Exchange the top two elements on the stack           |\n|`+`   | 2                  | Pop `b`, Pop `a`, push `a + b` onto the stack        |\n|`-`   | 2                  | Pop `b`, pop `a`, push `a - b` onto the stack        |\n|`*`   | 2                  | Pop `b`, pop `a`, push `a * b` onto the stack        |\n|`/`   | 2                  | Pop `b`, pop `a`, push `a / b` onto the stack        |\n|`over`| 2                  | Copy the 2nd element onto the top: `( a b -- a b a )`|\n|`rot` | 3                  | Rotate the top 3 elements: `( a b c -- b c a )`      |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpushfoo%2Fstacalc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpushfoo%2Fstacalc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpushfoo%2Fstacalc/lists"}