From 7f247c27073a273c4e0befacf6a94716c360383f Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 20 May 2023 11:34:47 -0400 Subject: feat: swap command --- forth.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'forth.js') diff --git a/forth.js b/forth.js index a169ca6..e589387 100644 --- a/forth.js +++ b/forth.js @@ -16,6 +16,12 @@ function forth(print = console.log) { '+' : () => { s.push(popNum() + popNum()) }, '*' : () => { s.push(popNum() * popNum()) }, '=' : () => { s.push(popNum() === popNum()) }, + 'swap' : () => { + const a1 = s.pop(); + const a2 = s.pop(); + s.push(a1); + s.push(a2); + }, 'then' : () => {/*Doing nothing skips the token*/}, 'if' : (initialIdx, tokens) => { if (!s.pop()) { -- cgit v1.2.3