Tachibana General Labs
Welcome to LAIN picture
2021-04-24 — Welcome to LAIN

LAIN is a small C like programming language.

LAIN is small C like language with a bytecode compiler written in Go. LAIN is based on the Monkey programming language from Thorsten Ball's Writing An Interpreter In Go textbook.

The original version of LAIN used a tree walking interpreter and the current version uses a single pass bytecode compiler with a companion virtual machine. LAIN code, after being interpreted or compiled with the bytecode compiler / VM combo is eventually executed in Go.

Getting started

$ go get gitlab.com/thatzopoulos/lain
$ ./lain -h
Usage: lain [options] [<filename>]
  -d    enable debug mode
  -e string
        engine to use (eval or vm) (default "vm")
  -i    enable interactive mode
  -v    display version information
  

To execute a lain script simply pass the name to the interpreter:

$ ./lain ./scripts/hello.lain

Scripts can be made executable by adding a suitable shebang line:

$ cat hello.lain
#!/usr/bin/env lain
puts( "Hello, Lain!" );

Execution then works as you would expect:

$ chmod 755 hello.lain
$ ./hello.lain
Hello, Lain!
  

If a script is not passed into the interpreter, the user will be dropped into a REPL.

Language Details

Basic

s1 = "hello LAIN"                     // strings
i = 1000                              // int
b = true                              // bool
a = [1, "2"]                          // array
h = {"name": "Lain", "OS": "Copland"} // hash
n = null                              // null
let add = fn(a, b) { a + b };         // function
let newAdder = fn(x) { fn(y) { x + y } }; // closure
  

Infix Operators

Arithmetic

5 + 5;
5 - 5;
5 * 5;
5 / 5;
  

Other

5 > 5;
5 < 5;
5 == 5;
5 != 5;
  

Prefix operators

!
-
  

Builtins

len() // Return the number of characters in a string
puts() // Takes an unlimited number of args, prints each on a separate line and returns null
push(array,value) // Returns a new array with value pushed onto the end of array
rest(array) // Returns a new array with the first element of array removed
first(array) // Returns the first element of the array
last(array) // Returns the last element of the array
  

Syntax Highlighting Plugins For Various Text Editors

Outbound Links:

incoming(3): dorcas compiler serial experiments lain

Last update on 2023-07-02, edited 4 times. +0/0fh