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

https://github.com/solarisstudio/piccodescript

A simple functional scripting language created in java
https://github.com/solarisstudio/piccodescript

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

Last synced: 23 days ago
JSON representation

A simple functional scripting language created in java

Awesome Lists containing this project

README

          

# PiccodeScript

> A simple interpreted, functional programming language.

[![Java CI with Maven](https://github.com/Glimmr-Lang/PiccodeScript/actions/workflows/maven.yml/badge.svg)](https://github.com/Glimmr-Lang/PiccodeScript/actions/workflows/maven.yml)

## 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

You can download binary releases from the Official website or visit the file server to find previous versions.

##### Latest

- [Official Release](http://piccodescript.fly.dev/)

##### Previous releases

- [Release Server](https://picasso-releases.fly.dev/piccodescript/)

## Build From Source

- Step 1 - Clone the repo.
```sh
$ git clone git@github.com:Glimmr-Lang/PiccodeScript.git
```

- Step 2 - Enter inside the dir.
```sh
$ cd PiccodeScript
```

- Step 3 - Run the build script.
```sh
$ ./all.sh
```

## Documentation
- [Standard library reference](https://piccodescriptdocs.fly.dev/)

# Example

###### Hello World

```js
import std.io

main :: () = IO::println("Hello, world")
```

###### Factorial

```js
import std.io

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

result := fact(5)
IO::println(result)
```

## 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

```
#### Note replace `Tag` with a release tag from the [releases](https://github.com/Glimmr-Lang/PiccodeScript/releases) page.

and then add the following code to your solution:

```java
Compiler
.compile("zero :: () = 0")
.execute(null);
```

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](https://www.lua.org/) - The simplicity
- [Rust](https://www.rust-lang.org/) - The flexibility
- [SML](https://www.smlnj.org/sml.html) - Functional programming concepts
- [Java](https://www.java.com/en/) - Threading model