DLiteScript

Syntax

Identifiers

Identifiers are names used for variables, constants, functions, and others. They must start with a letter or underscore, followed by any combination of letters, numbers, or underscores.

Examples:

Keywords

The following words are reserved and cannot be used as identifiers:

General keywords

KeywordDescription
varVariable declaration
constConstant declaration
funcFunction declaration
ifConditional statement
elseAlternative branch
forLoop statement
fromLoop range start
toLoop range end
breakExit loop
continueSkip to next iteration
returnReturn from function
importImport module
asImport alias
nullNull value
trueBoolean true
falseBoolean false

Type Keywords

TypeDescription
numberNumeric type
stringString type
boolBoolean type
anyAny type
errorError type

Literals

Number Literals

Numeric values support integers and floating-point numbers.

Examples:

String Literals

Strings are enclosed in double quotes and support escape sequences.

Examples:

Boolean Literals

Boolean values can be either true or false.

Examples:

Null Literal

The null keyword represents the absence of a value.

Array Literals

Arrays are declared with square brackets.

Examples:

Comments

Single-line comments start with //.

Operators

Arithmetic Operators

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
%Modulo
**Exponentiation

Assignment Operators

OperatorDescription
=Assignment
+=Add and assign
-=Subtract and assign
*=Multiply and assign
/=Divide and assign
%=Modulo and assign
**=Exponentiate and assign

Comparison Operators

OperatorDescription
==Equal to
!=Not equal to
>Greater than
>=Greater than or equal to
<Less than
<=Less than or equal to

Logical Operators

OperatorDescription
&&Logical AND
||Logical OR
!Logical NOT

Special Operators

OperatorDescription
...Spread operator
[]Index operator

Statements

Expression Statements

Any expression can be a statement:

1
2
printf("Hello\n")
x + 1

Block Statements

Statements can be grouped and scoped with braces:

1
2
3
4
{
  var x number = 1
  printf("%g\n", x)
}

Code Structure

DLiteScript programs are sequences of statements. Statements are typically separated by newlines, though multiple statements can appear on the same line. Braces {} create new scopes for variables and constants.

1
2
3
4
5
6
7
var x number = 10
printf("%g\n", x)

{
  var y number = 20
  printf("%g\n", y)
}
Improve this page