Skip to content

skalamark/gl

Repository files navigation

GLanguage

GLanguage Scripting Language written in Rust.

Install cli

Build from source using cargo:

$ git submodule init
$ git submodule update

$ cargo build --release

Getting Started

REPL (Read Eval Print Loop)

$ gl repl

Eval (Evaluate source from the command line)

$ gl eval "42"

Run (Run program from a script file)

$ gl run script.gl

Fmt (Format a script file)

$ gl fmt script.gl

Documentation

Syntax overview

Operators

It supports the general operations.

1 + 2 + (3 * 4) - (10 / 5)
!true
!false
+10
-5
"Hello" + " " + "World"

Variable bindings

Variable bindings, such as those supported by many programming languages, are implemented. Variables can be defined using the let keyword.

Format:

let <identifier> = <expression>

Example:

let x = 0
let y = 10
let function = fn(x) { x }

Literals

Literals implemented.

Integer

Integer represents an integer value.

Format:

42
200

Float

Float represents an float value.

Format:

3.1415

Boolean

Boolean represents a general boolean types.

Format:

true | false

Example:

true
false

let truthy = !false
let falsy = !true

String

String represents a string. Only double quotes can be used.

Format:

"<value>"

Example:

"GLanguage"
"Hello" + " " + "World"

Vec

Vec represents an ordered contiguous element. Each element can contain different data types.

Format:

[<expression>, <expression>, ...]

Example:

[1, 2, 3 + 3, fn(x) { x }, add(2, 2), true]
let vec = [1, true, fn(x) { x }]

vec[0]
vec[1]
vec[2](10)
vec[1 + 1](10)

Tuple

Tuple represents an ordered contiguous element. Each element can contain different data types.

Format:

(<expression>, <expression>, ...)

Example:

(1, 2, 3 + 3, fn(x) { x }, add(2, 2), true)

HashMap

HashMap represents data associating keys with values.

Format:

{<expression>: <expression>, <expression>: <expression>, ...}

Example:

let hashmap = {
  "name": "José Carlos",
  "age": 17,
  true: "a boolean",
  42: "an integer"
  3.1415: "an float",
  fn (){}: "an function",
}

hashmap["name"]
hashmap["a" + "ge"]
hashmap[true]
hashmap[42]
hashmap[4.1415 - 1]
hashmap[fn (){}]

Function

Function supports functions like those supported by other programming languages.

Format:

fn (<parameter one>, <parameter two>, ...) { <block statement> };

Example:

let add = fn(x, y) {
  x + y
}

add(10, 20)
fn add(x, y) {
  x + y
};

add(10, 20)

If return does not exist, it returns the result of the last evaluated expression.

let add_three = fn(x) { x + 3 }
let call_two_times = fn(x, f) { f(f(x)) }

call_two_times(3, add_three)

License

MIT © Skalamark