SPL : Stack Programming Language

By Jacques Bailhache ( jacques.bailhache@gmail.com ) February 2022

Data

SPL uses symbolic expressions like LISP. A symbolic expression is either an atom (number, string, symbol...), a pair of symbolic expressions, or a vector of symbolic expressions. A string is written between double quotes ("). A pair of symbolic expressions a and b is written (a . b). A list is represented by nested pairs, for example (a . (b . (c . (d . nil))) which may also be written (a b c). Writing of nested list can be simplified, for example (a b c (d e f)) may be written (a b c : d e f).

Program

A program is a list of instructions executed successively from left to right.

Context

A context represents the state of execution of the program at some time. A context contains the program, two stacks and an environment containing the values of variables.

Execution

Execution consists in repetitively taking the first instruction from the program and applying its effects on the context.

Example

This is an example of a program that pushes the symbol FOO on the main stack, then the symbol BAR, then makes a pair with them and prints the result :
(QUOTE FOO QUOTE BAR CONS PRINT)
(BAR . FOO)

Instructions

QUOTE

QUOTE pushes the next instruction to the main stack.

Combinators

Combinators are instructions acting on the program :

Stack manipulation instructions

Conditional

If the top of the main stack is true, (THEN a b) drops b and only a is executed, otherwise it drops a and only b is executed.

Symbolic expressions manipulation