# nrpl

0.1.0 • Public • Published

# Introduction to NRPL

## Description

NRPL is a stack-based language heavily inspired by Hewlett-Packard's RPL (from which it derives its name) and Forth. It was developed to give users the ability to do complex processing on their data server-side in a concise and secure manner.

Typical uses of NRPL are for querying, filtering, and transforming data. The language is general purpose, making it suitable for a variety of uses. This module was developed to fulfil the need for an interpreted that could be embedded in JavaScript applications to run untrusted, user-supplied code. For a full description of the language and its various options and commands, please refer to its complete specification.

## How it works

NRPL programs are sequences of commands, literals, and variables, which take arguments from, and return results to, a stack[PDF]. Being based on Hewlett-Packard's RPN, it uses a postfix notation.

### An example

Assume you would like to add the numbers 3 and 5 together:

Input

``````3 5 +
``````

Output

``````   1:   8
``````

Where `1:` refers to the bottommost stack level and `8` is the result of the operation.

### Another example (step by step)

Let us take a slightly more involved example, and calculate the volume of a sphere of radius 7.5, using the formula 4/3 π r3:

Input

``````4 3 / PI * 7.5 3 ^ *
``````

Output

``````   1:   1767.1458676442585
``````

The calculation happens as follows, step by step:

Description Input Stack
Enter the first number `4`
`   1:   4`
Enter the second number `3`
```   2:   4
1:   3```
Divide `/`
`   1:   1.3333333333333333`
Enter the symbolic constant π `PI`
```   2:   1.3333333333333333
1:   3.141592653589793```
Multiply `*`
`   1:   4.1887902047863905`
Enter the radius `7.5`
```   2:   4.1887902047863905
1:   7.5```
Enter the exponent `3`
```   3:   4.1887902047863905
2:   7.5
1:   3```
Exponentiate `^`
```   2:   4.1887902047863905
1:   421.875```
Multiply `*`
`   1:   1767.1458676442585`

A feature of postfix notation is that parentheses are never required. As long as enough stack levels are available (NRPL has a conceptually infinite stack) calculations can be of any arbitrary complexity.

## Installation

`npm install nrpl`

## Getting data in and out

Data is entered into the program via two mechanisms:

1. Direct input into the stack, as we have seen above.
2. Via variables, as we will see in a moment.

Retrieved may be retrieved from the stack or via assignment to global variables.

## Variables

There are two types of variables: “global” and “local”, both of which may be enabled or disabled independently.

### Global variables

These variables may be used to pass data into and out of the interpreter. For example, to persist data between calls. Globals may be read only, write only, read/write, or disabled altogether.

### Local variables

These variables are used within a single execution call, their values being lost once the script returns.

## Example instantiation with arguments

For a full description of NRPL, please refer to the specification.

## Package Sidebar

### Install

`npm i nrpl`

### Repository

gitlab.com/navlost/nrpl

3

0.1.0

MIT

81.3 kB

6