-
Notifications
You must be signed in to change notification settings - Fork 1
Syntax
The BType syntax is designed to feel natural for JavaScript programmers without creating awkward constructs for existing C++, Java, or C# programmers.
\-?(0|[1-9][0-9]*
Integers are expressed as an optional -
followed by a series of digits. If the integer is non-zero, the first digit may not be zero. -0
is not valid.
\-?(0|[1-9][0-9]*\.[0-9]+
Floating point numbers are expressed as an optional -
followed by a series of digits, a decimal point, and another series of digits. If the number is not between -1 an 1, the first digit may not be zero. -0.0
is not valid. If there is more than one digit to the right of the decimal point, the last digit may not be 0
.
-
true
andfalse
: Literal booleans evaluating to true and false, respectively -
null
: Represents the null version of the type that value is being assigned to
[a-zA-Z]\w+\<{type}(,\s*{type})*\>
Types which are abstract and can accept multiple sub-types (or "attributes") are represented as an identifier followed immediately by a <
, a comma delimited string of complex types, and a >
.
All statements must be followed by a semicolon.
int:foo = 123;
var foo = 123;
A variable declaration is defined as either the var
keyword or a type followed by a :
, followed by an identifier, a =
, and an expression.
var
may only be used if the type of the value being assigned can be determined at compile time.
func int:foo(int:bar, bool:zap) {
return 123;
}
A function declaration is defined as the func
keyword, optionally followed by a type and a :
, an identifier (the name of the function), a (
, an optional comma-delimited list of typed identifiers representing function parameters, a )
, a {
, an optional series of statements, and a }
.
If the function declaration doesn't specify a type on its identifier, it is assumed to be a void function and does not return a value. Non-void functions require a return statement with an expression of the return type.
return;
return 123;
A return statement may appear within the body of any function. It is the return
keyword optionally followed by an expression of the return type of the function the statement appears in. A return statement without an expression in a non-void function is invalid, as is a return statement with an expression in a void function.
An expression can be any of the following, or a literal.
(123)
(456 + 789)
((abc + 123) * 456)
A parenthesized expression is represented as a (
, followed by an expression, followed by )
. This has the highest precedence of all structures.
123 + 456
An infix operator is an expression, followed by a binary operator, followed by another expression. The specific binary operator determines the precedence of the operator.
!foo
-(123)
A unary operator is either a !
or a -
followed by an expression. All unary operators have the same precedence. All unary operators have a higher precedence than all binary operators.
foo()
A function call is an expression immediately followed by (
, a comma-delimited list of expressions, and a )
. Its return type is the return type of the function returned by the expression.