Sign inSign up

yuuza/sharprpn

By yuuza

•Updated over 5 years ago

An RPN programming language

Image
0

209

yuuza/sharprpn repository overview

⁠SharpRPN

SharpRPN is a stack machine with an RPN⁠ programming language, inspired by RPL⁠ on HP calculators.

SharpRPN image

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)

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⁠.

⁠Run in Docker Docker Image Size (tag)
docker run -it yuuza/sharprpn

Tag summary

Content type

Image

Digest

Size

42.8 MB

Last updated

over 5 years ago

docker pull yuuza/sharprpn