Gentee Programming Language > Documentation > Syntax Download documentation

func Function Declaration

A function consists of two parts: a declaration and a function body.

<func> ::= <function declaration><function body>

When you declare a function, you specify the keyword func, the type of its return value, its name, its attributes enclosed in angle brackets and its parameters enclosed in parentheses. Only the function name is required.

<function declaration> ::= func [<type name>] <function name> [<function attributes>] ['(' [<parameters declaration>] ')']

When you do not specify the type of its return value, the function does not return any values.
Function attributes:
 
entryis identified in functions run automatically before you make the major function call
mainis identified in the major function that will start the program execution

Only the last function main will be called automatically. It will be run after all entry functions have been called.
The functions which have either attribute specified above do not take any parameters.

Each parameter declaration is a comma-delimited series of parameter names with the type identifiers specified after a type name, then followed by a comma or space and a new type name and parameters. If a function takes no parameters, omit the identifier list and the parentheses in its declaration. You can define functions with the same name but with different parameters. In this case, when you call a function the compiler looks for a function with the same name and parameters.

<parameter declaration> ::= <variable name> [<array>]
<parameters declaration> ::= <type name><parameter declaration> { [','] <parameter declaration>} [<parameters declaration>]

When you declare a function that takes array parameters, specify its dimensions and the element type. The dimensions are surrounded by square brackets; if an array is one-dimensional, you can omit square brackets, otherwise a comma is used within brackets (a two-dimensional array needs one comma, a three-dimensional array needs two commas, etc. Array parameters are declared in a similar way to a variable of array type, nevertheless a number of elements in each dimension is not specified. If the element type differs from uint type, the type name is defined using the keyword of.

<array declaration> ::= ['['<natural number> { [','] <natural number>} ']'] [of <type name>]

func uint myfunc( uint a b c byte d, str st1, st2, arr marr[,] of uint )

Function parameters can be used as local variables.

A function body is a lowest-level block. Unlike the simple block, this block is likely to have subfunctions. A block consists of a series of expressions, statements and declarations of local variables.

<function body> ::= '{' (<block command> | <subfunction>) <block command> {<end-of-line> (<block command> | <subfunction>) } '}'

func uint myfunc <main>()
{
...
return 0
}

See also

    Subfunction subfunc declaration    The program structure


 Copyright © 2004-2006 Gentee Inc. All rights reserved.