GLanguage Scripting Language written in Rust.
Build from source using cargo:
$ git submodule init
$ git submodule update
$ cargo build --release
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
It supports the general operations.
1 + 2 + (3 * 4) - (10 / 5)
!true
!false
+10
-5
"Hello" + " " + "World"
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 implemented.
Integer
represents an integer value.
Format:
42
200
Float
represents an float value.
Format:
3.1415
Boolean
represents a general boolean types.
Format:
true | false
Example:
true
false
let truthy = !false
let falsy = !true
String
represents a string. Only double quotes can be used.
Format:
"<value>"
Example:
"GLanguage"
"Hello" + " " + "World"
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
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
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
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)