SharpBASIC is a very structured programming language. There is a general distinction between declaration/definition sections and execution sections. There are specific statements that can only occur in one of these sections.
Every SharpBASIC program has one main section. Even in a project with several modules, only one module can have a main section, which is the program's entry point. The main section is marked by the keyword main followed by a do..end block:
main do
end
In the main section is where program execution starts. Only execution statements (that includes compound do..end statements) can appear in the main section:
main do
print("Hello World");
end
Note the semicolon after the print statement. In SharpBASIC the semicolon is a statement terminator.
The prologue section is primarily a declaration section, where variables, subroutines and functions can be declared. It is also partially a definition section in that variables can optionally be defined with an initial value. The prologue section is not marked by special block delimiters, but rather by the fact that the statements are placed before the main section:
' This is the prologue section
dim msg: str = "Hello World";
' program entry
main do
print(msg);
end
Execution statements (that includes all do..end statements) can never appear in the prologue section. Trying to do so will result in an “illegal statement” error.
The epilogue section is a definition section reserved for subroutine and function definitions only. The epilogue section is always below the main section:
' prologue section (declarations, initial variable definitions)
decl sub helloWorld();
main do ' program start
helloWorld();
end ' program end
' epilogue section (subroutine, function definitions)
sub helloWorld()
do
print("Hello World");
end