No description
Find a file
Conrad Heinrich Carl 1714cb74e5 added modulo
2023-01-29 16:48:12 +01:00
.github/workflows remove auto test coverage 2023-01-22 17:35:34 +01:00
src added modulo 2023-01-29 16:48:12 +01:00
.deepsource.toml remove auto test coverage 2023-01-22 17:35:34 +01:00
.gitignore removed *.f 2023-01-27 13:39:39 +01:00
Cargo.lock added expected identifier test 2023-01-27 13:12:05 +01:00
Cargo.toml added expected identifier test 2023-01-27 13:12:05 +01:00
readme.md added variables 2023-01-29 16:42:20 +01:00

Stacky - a stack based programming language inspired by forth

Implemented

Explanation

Basic functions

  • DUB : duplicates the last item on the stack
  • SWAP : swaps the last two items on the stack
  • DROP : drops the last item on the stack
  • PUTS : takes a length n from the stack and the next n elements and prints them
  • EMIT (.) : takes and prints the last item on the stack

Word

A word defines a list of expressions that will be executed if the word is called. The basic syntax for a word is:

: [IDENTIFIER] [EXPRESSIONS] ;

Example:

: Add + ;
1 2 Add . 

will output 3

IF

The basic syntax for an if-statement is:

[CONDITION] IF [EXPRESSIONS] ELSE [EXPRESSIONS] THEN

The IF-Expression pops the last item from the stack and checks the condition. If the condition is met the if if-expressions-block is executed. Elsewise the else-expressions-block is executed.

A simple condition is: 1 1 = which evaluates to 1 (true).

LOOP

The basic syntax of a do-loop-expression is:

[LIMIT] [INDEX] DO [EXPRESSIONS] LOOP

The limit and the index get popped from the stack and are pushed to the loop-stack. Every loop-iteration the limit and the index get popped from the loop-stack to check if the looping condition (index < limit) is valid. After the loop-iteration the limit and the updated index are pushed back to the loop-stack.

Variables

Variables can hold data.

To assign data to a variable use the -> operator:

1 -> X

The number 1 is assigned to X. This operation will pop the 1 from the stack.

To get the data from an variable use the @ operator:

@ X

This puts the data in X on the stack.

For now variables are global so this:

: Test @ X . ;
2 -> X
Test

will print 2