https://github.com/lideming/sharprpn
An RPN programming language
https://github.com/lideming/sharprpn
csharp interpreter parser rpn rpn-calculator rpn-expression
Last synced: 4 months ago
JSON representation
An RPN programming language
- Host: GitHub
- URL: https://github.com/lideming/sharprpn
- Owner: lideming
- License: mit
- Created: 2021-04-08T09:16:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-17T16:36:13.000Z (about 5 years ago)
- Last Synced: 2024-12-31T01:42:12.947Z (over 1 year ago)
- Topics: csharp, interpreter, parser, rpn, rpn-calculator, rpn-expression
- Language: C#
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SharpRPN
SharpRPN is a stack machine with an [RPN](https://en.wikipedia.org/wiki/Reverse_Polish_notation) programming language,
inspired by [RPL](https://en.wikipedia.org/wiki/RPL_(programming_language)) on HP calculators.

Use as a calculator:
```
Input: 1
# │ Value │ Type
───┼───────┼───────
1 │ 1 │ Int32
Input: 2
# │ Value │ Type
───┼───────┼───────
2 │ 1 │ Int32
1 │ 2 │ Int32
Input: +
# │ Value │ Type
───┼───────┼───────
1 │ 3 │ Int32
Input: 3 4 + *
# │ Value │ Type
───┼───────┼───────
1 │ 21 │ Int32
Input: 1 2 3 * 4 + +
# │ Value │ Type
───┼───────┼───────
2 │ 21 │ Int32
1 │ 11 │ Int32
```
Drop an item from stack or clear all items:
```
# │ Value │ Type
───┼───────┼───────
2 │ 21 │ Int32
1 │ 11 │ Int32
Input: drop
# │ Value │ Type
───┼───────┼───────
1 │ 21 │ Int32
Input: clear
Stack empty
```
Set value to variable:
```
Input: 1 'foo' sto
Stack empty
Input: foo
# │ Value │ Type
───┼───────┼───────
1 │ 1 │ Int32
```
Codeblocks:
```
Input: { 'hello world!' 1 2 + }
# │ Value │ Type
───┼──────────────────────────┼───────────
1 │ { 'hello world!' 1 2 + } │ CodeBlock
Input: eval
# │ Value │ Type
───┼──────────────┼────────
2 │ hello world! │ String
1 │ 3 │ Int32
```
Input and condition:
```
Input: { 'Correct\n' print } { 'Wrong\n' print } "What's the answer? " print input '42' == evalifelse
What's the answer? 42
Correct
```
## Try it now
### Build and run from source
(.NET Core 3.1 SDK required)
```shell
git clone https://github.com/lideming/SharpRPN.git
cd SharpRPN
dotnet run
```
### Run prebuilt binaries
(.NET Core 3.1 Runtime required)
Download the latest build from [Github Actions](https://github.com/lideming/SharpRPN/actions).
### Run in Docker [](https://hub.docker.com/r/yuuza/sharprpn)
```shell
docker run -it yuuza/sharprpn
```