An open API service indexing awesome lists of open source software.

https://github.com/glimmr-lang/piccodescript

A simple functional scripting language created in java
https://github.com/glimmr-lang/piccodescript

compiler functional functional-programming interpreter java jvm jvm-languages language script scripting-language

Last synced: 6 months ago
JSON representation

A simple functional scripting language created in java

Awesome Lists containing this project

README

          

# PiccodeScript

> A simple interpreted, functional programming language.

## Why?

PiccodeScript started as a dsl for an image editor (Picasso Code) I was building, and overtime
I fell in love with the simple syntax and I wanted to make to its own project, possibly for
embedding in my java programs or for general scripting.

## Installation
>> TODO:

## Example

###### Hello World
```js
import std.io

function main() = IO.println("Hello, world")

main()
```

###### Factorial

```js
import std.io

function fact(x=1) =
when x {
is 0 -> 1
is 1 -> 1
else -> x * fact(x - 1)
}
```

## Embedding API

To use the language in your project simply add it your `pom.xml` file as a dependency:

```xml


jitpack.io
https://jitpack.io

com.github.Glimmr-Lang
PiccodeScript
Tag

```

and then add the following code to your solution:

```java
Compiler.compile("function zero() = 0")
```

If you want to get a list of AST nodes do this:

```java
Compiler.prepareGlobalScope();
List nodes = Compiler.parse(input);

// Then you can execute them or do what you want
for (var expr: nodes) {
expr.execute();
}
```

To add symbols to the current scope you can do the following:

```java
Context.top.putLocal("hello", new PiccodeString("Hello, world"));

Compiler.compile("hello + 20"); // concate hello, world and 20
```

## Inspired by
- Lua - The simplicity
- Rust - The flexibility
- SML - Functional programming concepts