Skip to content

SolarisStudio/PiccodeScript

Repository files navigation

PiccodeScript

A simple interpreted, functional programming language.

Java CI with Maven

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
Previous releases

Build From Source

  • Step 1 - Clone the repo.
$ git clone git@github.com:Glimmr-Lang/PiccodeScript.git
  • Step 2 - Enter inside the dir.
$ cd PiccodeScript
  • Step 3 - Run the build script.
$ ./all.sh

Documentation

Example

Hello World
import std.io

main :: () = IO::println("Hello, world")
Factorial
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:

<repositories>
	<repository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</repository>
</repositories>

<dependency>
	<groupId>com.github.Glimmr-Lang</groupId>
	<artifactId>PiccodeScript</artifactId>
	<version>Tag</version>
</dependency>

Note replace Tag with a release tag from the releases page.

and then add the following code to your solution:

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

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

Compiler.prepareGlobalScope();
List<Ast> 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:

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
  • Java - Threading model