-
Notifications
You must be signed in to change notification settings - Fork 11
Isla language guide
This guide will cover the core Isla language.
Tokens in the language are delimited by whitespace. Whitespace means spaces, tabs and new lines. All tokens, besides strings, are case insensitive.
Expressions in the language are delimited by new lines.
An Isla program can only have one block.
Regardless of the number of new lines between expressions, all expressions in the program will belong to one block.
An Isla program has a single, global scope. All variables, types and functions are always in scope.
The environment consists of two things.
First, the return value of the previously executed expression. If an expression does not return anything, the return value is nil
.
Second, the current context. This contains a map of all available object types. It also contains a map of variables and functions that are in scope. This second map amounts to every variable ever instantiated and all the built in functions.
The following words are reserved: is
, a
, list
, add
, remove
, to
, from
, true
, false
.
Variables are denoted by single words that match this regex: [A-Za-z]+
.
Simple (non-object) variables can be strings or integers references to other variables and are assigned, thus:
age is 1
name is 'Mary'
friend is isla
See the Objects section.
An integer literal should match this regex: [1-9][0-9]*
. Notice that an integer must start with a digit between 1 and 9.
Currently, arithmetic is not supported. This will probably change.
A string literal is delimited by a pair of single quotation marks '
or a pair of double quotation marks "
. Contents must match this regex: ^('|\")[A-Za-z0-9 \.,\\']+\1$
.
No string operations are supported, besides assignment to a variable.
Not yet implemented.
Objects can be of an existing type, like list
, or defined by the programmer. Objects have zero or more attributes that may be set. Objects have no methods.
isla is a person
zach is a giraffe
You can see that, in order to make a new type, giraffe
, you simply name the type.
Objects may have any attribute name assigned on them, regardless of whether they were made from built-in and programmer-defined types.
isla is a person
mary is a person
isla age is 2
isla sound is 'pop'
isla auntie is mary
isla sdfjhsdhjfshjejhsscf is 3
Notice how integers, strings and objects may be assigned to an object attribute.
List literals are not supported. Lists can contains any combination of integers, strings and objects. Lists may contain other lists.
Lists are a little strange. They can only contain one instance of a variable, but can contain many instances of two literals that are identical. For example:
basket is a list
add "banana" to basket => ["banana"]
add "banana" to basket => ["banana" "banana"]
banana is a fruit
add banana to basket => ["banana" "banana" banana]
add banana to basket => ["banana" "banana" banana]
age is 1
add age to basket => ["banana" "banana" mary age]
add age to basket => ["banana" "banana" mary age]
Think of this in terms of references. If you put a banana object into a list twice, you have put in two place holders that lead back to the same place. Thus, the banana object only appears in the list once. Literals are not references; they are actual things. Therefore, when you put a string "banana" in and another string "banana" in, these are two separate things, so they both appear in the list.
items is a list
items is a list
add 'hi' to items
items is a list
remove 'bye' from items
items has 'hi'
Returns true or false. Not yet implemented.
Individual items in lists may not be accessed.
I haven't decided how to do these yet. However, probably only if
statements will be allowed, and they will occupy the same line as their single conditional branch, like: open door if player has key
.
It is not possible to define functions. However, it is possible to call built in functions. Currently, functions may take a maximum of one parameter. This may change.
A function invocation:
write name
It is possible to pass object attributes as parameters:
write mary age
write
This function prints out the passed argument to the standard output. It also returns the argument.