Skip to content
Matt Basta edited this page Feb 17, 2015 · 3 revisions

The BType syntax is designed to feel natural for JavaScript programmers without creating awkward constructs for existing C++, Java, or C# programmers.

Literals

Integers

\-?(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.

Floating point numbers

\-?(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.

Keywords

  • true and false: Literal booleans evaluating to true and false, respectively
  • null: Represents the null version of the type that value is being assigned to

Complex Types

[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 >.

Statements

All statements must be followed by a semicolon.

Variable Declarations

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.

Function Declarations

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 Statements

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.

Expressions

An expression can be any of the following, or a literal.

Parenthesized Expression

(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.

Infix Operators

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.

Unary Operators

!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.

Function Calls

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.