pounce-lang / js-core

Core elements of a Pounce (pounce-lang) interpreter, parser, preprocessor written in TypeScript. Pounce types are being developed (a preprocess type checker is in beta)
https://pounce-lang-show-case.netlify.app/
6 stars 0 forks source link
concatenative-programming-language forth-like interpreter joy-language programming-language

Pounce-lang/js-core

Pounce is a small concatenative programming language, developed mostly because there was no easy to use version of Joy-lang. This implementation of the language includes a parser and an interpreter (called js-core, but written in TypeScript) (also see: c-core and py-core for microprocessor versions implemented in "C" and "Python"). A core dictionary of Pounce words ("words" in concatenative parlance are "pure functions") can be augmented or replaced with a custom, perhaps more efficient, expressive or both, dictionary.

A demo is here.

about Pounce

Pounce follows in the footsteps of Forth, Joy, Cat and Kitten, in that it is, Concatenative and a 'stack-based' language. To summarize, Pounce has:

Quick Start

To start Pounce programming in the browser, you can try this sampler. OR install Pounce into a Typescript or Javascript project

npm install pounce-lang/js-core

and use it like this

import { interpreter } from '@pounce-lang/core';

const interp = interpreter('3 4 +');
const { value } = interp.next();
console.log(value.stack)

Try it in RunKit

RunKit https://runkit.com/embed/rq1ez0jvgfsh

// Run a small Pounce program that doubles 21.
// When logLevel > 0, intermediate states of the stack and program are displayed. 
var core = require("node_modules/@pounce-lang/core")
var interp = core.interpreter(core.parse("21 dup +"), {logLevel:1});
var pounceState = interp.next();
while (pounceState.value.active) {
  const stack = core.unParse(pounceState.value.stack);
  const prog = core.unParse(pounceState.value.prog);
  console.log(`${stack} | ${prog}`);
  pounceState = interp.next();
}
console.log(pounceState.value.stack);

to peek in on the code, build and test:

clone this repo, then

npm i
npm run build

and run the tests

npm run test