Bonzai Syntax
Bonzai is a simple, yet powerful language that is designed to be easy to read and write. It is designed to be a language that is easy to learn and use, while still being powerful enough to handle complex tasks. This document will provide an overview of the Bonzai language syntax and its design.
Literals
Bonzai has several types of literals, including strings, numbers, and booleans. Strings are enclosed in double quotes, numbers are written as decimal numbers, and booleans are written as either true
or false
.
Variables
Variables denote many things in Bonzai, such as variable identifiers, constant definitions, live variables, and mutable variables.
Variable identifiers
Variable identifiers are used to represent a value behind a name. They follow some naming rules to be valid:
- They must start with a letter or an underscore.
- They can contain letters, numbers, and underscores.
- They are case-sensitive.
Constant definitions
Constant definitions are used to define a value that cannot be changed, once it has been assigned. They are declared using the let
keyword.
Live variables
Live variables are used to define a value that can be updated and that will update all references to it. They are declared using the live
keyword.
Mutable variables
Mutable variables are used to define a value that can be changed after it has been assigned. They are declared using the mut
keyword.
Functions and anonymous functions
Functions are used to define a block of code that can be called multiple times with different arguments. They are declared using the fn
keyword.
In Bonzai, there is no return statement. The last expression in a function is automatically returned.
Anonymous functions are functions that are defined without a name. They are declared using the fn
keyword followed by the arguments and the function body.
Control structures
Bonzai has several control structures, including if
, else
, while
, and match
.
If statements
While loops
Match expressions
Actors and interfaces
Actors are used to define objects that can communicate with each other. They are declared using the actor
keyword. Each actor must implement an interface that defines the types of the events it can receive.
Module imports
Extern functions
Extern functions are used to define functions that are implemented in another language. They are declared using the extern
keyword.
Types
Bonzai supports custom datatype definitions using the type
keyword.