o
odin.langpkg.dev
packages / library / calcstack

calcstack

7eaf647library

A minmal stack based interpreted language.

MIT · updated 1 month ago

Calcstack

A minimal stack based language using reverse polish notation.

Features

  • Arithmetic operations: + - * / %
  • Control flow: loops and conditionals

Syntax

  • [Arithmetic]: consumes two numbers and adds the result on the stack 4 1 - -> [3]
  • [number]: add a number to the stack
  • dup: duplicate top of stack
  • swap: swap top two of the stack
  • drop: drop top of stack
  • print: print top of stack (consumes top of stack)
  • if-[cmp] ... else ... end-if: consumes top two of stack for comparison and executes left or right based on result.
  • loop-[cmp] ... end-loop: consumes top two of stack before each loop for comparison
  • proc:[name] ... end-proc: defines a procedure, it can be called using [name]
  • [cmp]: can be one of eq,neq,lt,gt,leq,geq

Examples

even number in the first 20

first 20 squares