Chapter 6. Statements and Flow Control
At the end of the previous section, we discussed expressions and statements. In this section we will go into how statements are used to build functions and how functions make up a program.
function
The function is the basis for every program in SIMPOL. The simplest program
consists of a single function called main
. When the
main
function is exited, the program also ends. A function
begins with a function statement. The function statement consists of the
function keyword, followed by the name of the function which
must be a valid identifier, followed by the left
parethesis, followed by zero or more parameters in the format
type identifier
white space parameter name
optionally followed by an equals sign and a default value for the
parameter. Multiple parameters are separated by commas. The parameters are
then followed by a closing right parenthesis. If the function is part of a
library and should be exported, then the export
keyword
follows the closing parenthesis. The complete syntax diagram can be seen
below:
function
functionname ([typename
parameter
[=value]] [, typename
parameter [=value]] [, …])
[export]
![]() | Tip |
---|---|
One point worth noting is that in the function declaration there is no indication of whether or not there is a return value, nor if there is one any information about its type. That is mainly because the return value follows the end function statement and the type may not be known when the function is written or even when it is compiled. |