Language Reference
Variables
Decalrations
- Variables are declared with the "let" keyword, similar to js.
- Variables are not typed.
- Vars are scoped within blocks just like other C style languages.
- Declarations can be chained with comma operator.
- Redeclaring variable in the same scope is a resolution error
Primitives
- Nil: default value for uninitialized variables, similar to null or undefined in
other languages.
- String: any number of single or double quotes wrapping text, though number of quotes
on both sides must match
- Number: just like js, all numbers are floating point numbers, however int() function
is provided to floor the number to int.
- Boolean: true and false are special constants. Values are implictly casted to bool
when evualating in context where a bool is expected.
- Nil: always false
- String: true iff length greater than 0
- Number: true iff not equal to 0
- Array: true iff not empty
- Objects: all objects are considered true
- Array: Can either be declared with initial value: "let x = [1, 2, 3]", or without:
"let x = [](10)". Undeclared arrays are filled with nils.
Complex types
Functions, objects, and class constructor are all values that can be assigned to
variables.
Operators
Arithmetics
The usual arithmetic operators are supported
Logicals
Logical operator mostly follow other languages, except that both keyword and symbols are
supported for AND, OR, and NOT. Chained compares are supported with logics similar to
python's chained compare. Short cercuiting is implemented.
Other Operators
Array index operator
Accessing value by index is done via the "var[idx]" syntax. Accessing by index also gets the
reference of the position so that they can be assigned. This operator is supported for:
- Array: 0 indexed, access array element at that posiition.
- String: gets the character at the position. Assignment acts like string
concatonation
- Number: gets the digit at the position, where 0 index is the "ones" digit of the
number.
Floating point number is converted to integer before finding the digit.
Assignment at index will try to append digits to the number, if none numerical numbers
are appended, the value is converted to a string instead.
Currently implementation for numeric access is flawed, FIXME.
Assignment operator
Assignment operations behaves simiarly to other C-style languages, that it assigns the value
on the right side to a assignable reference on the left side. Only variables and array-like index
are assignable. Assignment is a expression that evaluates to the value being assigned, after
the assignment. Comma Operator
Comma operator behaves similar to other C-style languages, where each comma separated expression
are sequentially evaluated, but the entire express evaluates the to value of left most expression.
Probe / Question mark operator
The probe operator is currently not implemented. The intention is that it would print debug info
of the precending expression, then eval it, and print the eval results. Ideally there could also
be some new syntax introduced so that user can specify otpions to print more info, such as the
statement the ? belongs to, or perhaps the current block, function declarions, etc.
Operator precedence
Operator precedence is designed to follow math order of operations, and also generally follows
conventions of C style languages.
- Brace: (...), variable, literals, keyword constants, function calls
- Probe ?
- !, - (unary)
- ^ (exponentials)
- / * (multiplication and division)
- - + (addition and subtraction)
- == != < > <= >= (logical compares)
- and or && || (conjunction, disjunction)
- a | x : y (Ternery)
- = (assignment)
- , (comma operator)
Statements
Conditionals
It works the way you think it does.
Loops
Works the way you think it does. Note that "+=" and "-=" operators are not implemented in the
language. Also note that using continue and break out side of loop is a resolution error.
Expression Statement
Any valid expression can be a statement on their own, though this is only useful in case of function
calls.
Print statement
Print is implemented as a keyword, like Python 2 (though you can wrap print content with () to
pretend it is a function). Printing multiple items is not supported.
Functions
Declarations
Functions are declared with the "function" keyword.
But, the keyword can any letters
from the word "function", as long as they are in order and have at least 2 letters. The
following are all valid function declarations.
Arguments and Overloads
Functions can take any number of arguments, and args are not typed. Functions of the same name
but different number of args can be declared. This looks like function overloading in other languages,
but here they are practically different functions. Declaring multiple functions with the same
name and number of args in the same scope is considered a resolution error.
Function as values
Reference to declared functions can be stored in variables, passed around, and returned from
functions. Lambda functions are not supported (though the current architecture can easily do
:/).
Closure
Js style function closure is implemented. When a function is created/declared, it takes a snapshot
of its execution context, so in a way it remembers the already declared variables and functions.
So that values that appears to be no longer accessible is still tracked by the function. See
the example below.
Classes
Not implemented yet.