POWERMAN
"In each of us sleeps a genius...
and his sleep gets deeper everyday."

Operators

Limbo operators have the following associativity and precedence, listed from highest precedence to lowest.

left            .
left            ->
left            () [] ++ --

nonassoc        ! ~ len hd tl tagof
nonassoc        big byte int real string fixed(0.0,0.0)
nonassoc        + - * ref       (unary)

right           <-
right           **
left            * / %
left            + -
left            << >>
left            < > <= >=
left            == !=
left            &
left            ^
left            |
right           ::
left            &&
left            ||
left            load
right           = := &= |= ^= <<= >>= += -= *= /= %= **=

Syntax summary (Updated Dec 2012)

This syntax was defined using current limbo source (/appl/cmd/limbo/limbo.y) to be used as reference instead of outdated syntax summary in “The Limbo Programming Language”.

Actual syntax allowed in limbo programs is slightly more restrictive than described here because limbo do extra syntax checks after parsing source (not every kind of type or expression allowed where you see type or expression below, for example only kind of expressions supported by spawn is function call).

Comments

Comments are everything from # to the end of line. Using comments in this format you can set current location (used for reporting warnings/errors):

#line 123 "/path/file.b"

Identifiers and constants

identifier:

[a-zA-Z_][a-zA-Z_0-9]*

string-constant:

`[^`]*`
"([^"\\\n]|\\[\\'"abtnvfr0]|\\u[0-9a-fA-F]{4})*"

constant:

'([^\\\n']|\\[\\'"abtnvfr0]|\\u[0-9a-fA-F]{4})'
[0-9]+(r[0-9A-Za-z]+)?
([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)?

identifier-list:

identifier
identifier-list , identifier

nil-or-identifier:

identifier
nil

nil-or-identifier-list:

nil-or-identifier
nil-or-identifier-list , nil-or-identifier

tuple-or-nil-or-identifier:

nil-or-identifier
( tuple-or-nil-or-identifier-list )

tuple-or-nil-or-identifier-list:

tuple-or-nil-or-identifier
tuple-or-nil-or-identifier-list , tuple-or-nil-or-identifier

Program

program:

implement identifier-list ; top-declaration-sequence

top-declaration-sequence:

top-declaration
top-declaration-sequence top-declaration

top-declaration:

declaration
tuple-or-nil-or-identifier = expression ;
tuple-or-nil-or-identifier := expression ;
module-declaration
adt-declaration
function-definition

declaration:

include string-constant ;
identifier-list : import identifier ;
identifier-list : type type ;
identifier-list : con expression ;
identifier-list : exception tuple-typeopt ;
identifier-list : type ;
identifier-list : type = expression ;

Types

basic-type:

byte
int
big
real
string

fixed-type:

fixed ( expression , expression )
fixed ( expression )

type:

basic-type
fixed-type
ref type
chan of type
array of type
list of type
tuple-type
identifier poly-typeopt
type . identifier poly-typeopt
type -> identifier poly-typeopt
fn poly-argopt function-arg-ret poly-foropt raisesopt

type-list:

cyclicopt type
type-list , cyclicopt type

tuple-type:

( type-list )

poly-type:

[ type-list ]

Expressions

assignment-operator: one of

= &= |= ^= <<= >>= += -= *= /= %= **=

binary-operator: one of

** * / % + - << >> < > <= >= == != & ^ | :: && ||

monadic-operator: one of

+ - ! ~ ref * ++ -- <- hd tl len tagof

expression-list:

expression
expression-list , expression

expression:

monadic-expression
expression := expression
expression <- = expression
expression assignment-operator expression
expression binary-operator expression
load identifier expression

monadic-expression:

term
monadic-operator monadic-expression
array [ expression ] of type
array [ expressionopt ] of { array-init-element-list ,opt }
list of { expression-list ,opt }
chan of type
chan [ expression ] of type
array of basic-type monadic-expression
basic-type monadic-expression
fixed-type monadic-expression
identifier monadic-expression

term:

nil-or-identifier
term ( expression-listopt )
( expression-list )
term . identifier
term -> term
term [ expression-or-type-list ]
term [ expressionopt : expressionopt ]
term ++
term --
string-constant
constant

expression-or-type-list:

expression-or-type
expression-or-type-list , expression-or-type

expression-or-type:

expression
type-expression

type-expression:

basic-type
array of type
list of type
cyclic type

Module, ADT

module-declaration:

identifier-list : module { module-member-sequenceopt } ;

module-member-sequence:

module-member
module-member-sequence module-member

module-member:

identifier-list : type ;
identifier-list : type type ;
identifier-list : con expression ;
identifier-list : exception tuple-typeopt ;
adt-declaration

adt-declaration:

identifier-list : adt poly-argopt { adt-member-sequenceopt } poly-foropt ;
identifier-list : adt poly-argopt poly-for { adt-member-sequenceopt } ;

adt-member-sequence:

adt-member
adt-member-sequence adt-member

adt-member:

identifier-list : cyclicopt type ;
identifier-list : con expression ;
pick { pick-member-sequence }

field-sequence:

identifier-list : cyclicopt type ;
field-sequence identifier-list : cyclicopt type ;

pick-member-sequence:

pick-tag-list => field-sequenceopt
pick-member-sequence pick-tag-list => field-sequenceopt

pick-tag-list:

identifier
pick-tag-list or identifier

poly-arg:

[ identifier-list ]

poly-for:

for { poly-member-sequence }

poly-member-sequence:

identifier-list => field-sequenceopt
poly-member-sequence identifier-list => field-sequenceopt

Function

function-definition:

function-name-part function-arg-ret poly-foropt raisesopt { statementsopt }

function-name-part:

identifier poly-argopt
function-name-part . identifier poly-argopt

function-arg-ret:

( function-varg-listopt )
( function-varg-listopt ) : type

function-varg-list:

function-arg-list
function-arg-list ,

function-arg-list:

function-arg
function-arg-list , function-arg

function-arg:

nil-or-identifier-list : type
nil-or-identifier-list : self refopt identifier poly-typeopt
nil-or-identifier-list : self refopt type . identifier poly-typeopt

raises:

raises tuple-or-nil-or-identifier

Statements

statements:

declaration
statement
statements declaration
statements statement

statement:

expressionopt ;
{ statementsopt }
{ statementsopt } exception identifieropt { qual-statement-sequence }
if ( expression ) statement
if ( expression ) statement else statement
labelopt for ( expressionopt ; expressionopt ; expressionopt ) statement
labelopt while ( expressionopt ) statement
labelopt do statement while ( expressionopt ) ;
labelopt case expression { qual-statement-sequence }
labelopt alt { qual-statement-sequence }
labelopt pick identifier := expression { pqual-statement-sequence }
break identifieropt ;
continue identifieropt ;
return expressionopt ;
spawn expression ;
raise expressionopt ;
exit ;

label:

identifier :

qual-list:

qualifier
qual-list or qualifier

qualifier:

expression
expression to expression
*

pqual-list:

pqualifier
pqual-list or pqualifier

pqualifier:

identifier
*

qual-statement-sequence:

qual-list => statementsopt
qual-statement-sequence qual-list => statementsopt

pqual-statement-sequence:

pqual-list => statementsopt
pqual-statement-sequence pqual-list => statementsopt

array-init-element-list:

array-init-element
array-init-element-list , array-init-element

array-init-element:

expression
expression => expression
qual-list => expression