Functions

Functions can be declared the same places as other declarations. The syntax for functions is defined by the grammar for Function:

Function        ::= Type ID '(' Params ')' Block 
Params		::= Param (',' Param)*
Param           ::= Type [ & ] ID ArrayDecl*
Block	        ::= '{' Declarations Statement* '}'
Statement       ::= Block
                 | ';'
                 |  Expression ';'
	         |  ForLoop
		 |  Iteration
	         |  WhileLoop 
	         |  DoWhileLoop 
	         |  IfStatement 
		 |  ReturnStatement
ForLoop	        ::= 'for' '(' Expression ';' Expression ';' Expression ')' Statement 
Iteration	::= 'for' '(' ID ':' Type ')' Statement
WhileLoop       ::= 'while' '(' Expression ')' Statement
DoWhile         ::= 'do' Statement 'while' '(' Expression ')' ';'
IfStatment      ::= 'if' '(' Expression ')' Statement [ 'else' Statement ]
ReturnStatement ::= 'return' [ Expression ] ';'

The Declarations non-terminal is defined in the section on declarations and the Type non-terminal is defined in the section on types.

Call by Reference and Call by Value

When passing parameters to functions (and templates, see the section on templates) this can be done using either reference parameters or value parameters. Default is value. Reference parameters are explicitly declared using the & sign. E.g. bool &b.

Iteration

The keyword for has two uses. One is a C/C++/Java like for-loop, and the other is a Java like iterator. The latter is primarily used to iterate over arrays indexed by scalars which is useful in symmetry reduction. It can however also be used to iterate over normal arrays. It is however important to notice that opposed to Java, a Type opposed to a quantity in Java.

The scope of ID is the inner statement.

Examples