Futurebasic/language/syntax

Introduction to the FB Language
An FB program consists of a series of statements, and optional statement labels. Usually you will write each statement on a separate line; however, it’s possible to put multiple statements on a single line, and conversely a single statement may span multiple lines.

You can write multiple statements on a single line by separating each pair of statements with a colon, as in this example: A = 7 * B : Print score(A) : Fn doSum(x)

If a line ends with the continuation character, the (last) statement on that line continues on the next line. The continuation character looks like this: ¬, and it is typed by entering Option-L. Example: myArray(numberDogs, numberCats, numberPorcupines) ¬ = Fn createMenagerie(Mid$(animalName$(x), ¬ nameOffset, 4), vetNumber) While you can safely insert a line-break character [option-L] in a quoted string, elsewhere it is wise to only insert line-break characters between statements, and definitely not to mix them with block statement. For those who still use line numbers, any line in your program (except lines which follow a continuation character) may begin with a line number.

Certain special statements mark the beginning or end of a “block structure.” A statement which opens or closes a block structure should not appear with any other statement on the same line. Such statements include the following:

Begin Enum... End Enum Begin Globals... End Globals Begin Record... End Record BeginAssem... EndAssem Compile Long If... Compile Xelse... Compile End If Dim Record... Dim End Record Do... Until EnterProc... ExitProc EnterProc%... ExitProc% For... Next Local Fn... End Fn Long Fn... End Fn Long If... Xelse...End If Select Case... End Select Case While... Wend
 * 1) If... #Else... #EndIf

Line Numbers
Any line in your program (except lines which follow a continuation character) may begin with a line number. A line number must be an integer in the range 1 through 65534, and no two lines may have the same number. At least one space character should separate the line number from the first statement in the line. Example: 140 Print "Hello": Beep Line numbers can be useful for identifying a particular location in your program, as a target for statements such as  or. However, line numbers are considered an antiquated syntax feature, and their use is generally discouraged.

Statement Labels
A statement label is another way to identify a particular location in your program. A statement label must appear on a line by itself, and the same label can’t appear more than once in your program. Depending on your Preferences settings, you can express a statement label in the following ways:

A string of characters inside double-quotes. Example: "My First Label" A string of non-space characters followed by a colon. This kind of label is only available if the “Allow QuickBasic Labels” preference is set (See the Editor manual). Example: Label17: Like line numbers, statement labels can be useful if your program contains statements like or ; or if your program uses the   or   functions.

Note that when the preference for QuickBASIC labels is turned on a FutureBASIC statement may look like a QuickBASIC label to the compiler. Example: Print:Stop:Rem this won't work with QB labels On Because QuickBASIC labels require that no space be present between the text and the colon, you can side step possible errors as follows: Print : Stop : Rem note the space before the colon

Executable and Non-executable Statements
Every statement in FB is either an executable statement or a non-executable statement.

Executable statements represent instructions which are to be performed when the program is run. When you run your program, a given executable statement may be performed once, or more than once, or not at all, depending on the program conditions. The order in which executable statements are performed is not necessarily the same as the order in which they appear in your program. Examples of executable statements are: ;  ;  ;.

Non-executable statements represent instructions which tell the FB compiler how to build your program. They help the compiler to determine how to allocate memory, and how to interpret and compile other statements in your program. The order in which non-executable statements appear in your program is important: when the compiler builds your program, it scans all statements from top to bottom, and a non-executable statement can only affect the interpretation of lines which appear below it. You cannot change the effect of a non-executable statement by putting it inside a “conditional execution” block such as, or  . However, you can conditionally include or exclude a non-executable statement from the program by putting it inside a  block. Examples of non- executable statements are: ;  ;  ;.

Program Layout and Order of Execution
Parts of your program may be located within function blocks and procedure blocks. Function and procedure blocks are blocks of statements which are surrounded by the following pairs of statements: Local Fn...End Fn Long Fn...End Fn EnterProc...ExitProc Statements which are outside of all function and procedure blocks are said to belong to the “main” part of your program. “Main” statements may either precede function & procedure blocks, or follow them, or both.

When your program runs, the first executable statement that appears in “main” is the first statement that actually executes. After that, the order of execution depends on the specifics of the program: normally, statements are executed in the order in which they appear in “main,” but the flow of execution can be altered by statements like ;  ;  ; ; etc. Function blocks and procedure blocks are not executed until they are explicitly “called,” using a statement like. The program stops when it reaches an  or   statement, or when it reaches the last statement in “main.” Note that if there are no executable statements in “main,” your program won’t do anything.

Identifiers
An identifier is a name that you make up to identify something in your program. In FB, identifiers are used to name the following kinds of things:


 * variables;
 * arrays (see below);
 * user-defined functions (see the,   etc. statements);
 * user-defined data types (see the  and   statements);
 * record fields (see the  and   statements);
 * symbolic constants (see the “Constant declaration” statement).

In FB, an identifier can have any length up to 245 characters. It must start with a letter; its subsequent characters can be any combination of letters, numeric digits, and underscore characters ( _ ) (symbolic constant names should not contain embedded underscores). Identifiers which represent variables, arrays and function names may also be followed by a “type-identifier suffix,” which is a 1- or 2-character symbol that specifies the item’s data type (see Appendix C for a list of type-identifier suffixes). Identifiers are “case-insensitive,” so the identifiers and  are both recognized as the same identifier.

You can use the same identifier to name two different things, as long as the context makes it clear which thing is being referred to. For example, your program may have a variable identified as, and also a local function identified as  ; FB can distinguish between these two, because references to local functions are always preceded by the  keyword in your program.

Variables
A variable can be thought of as a “named container for data.” There are a number of different ways to represent variables in FB; see Appendix B for more information. Every variable is associated with a “data type,” which determines the amount of memory that the variable occupies, and how the variable’s value is interpreted. There are a number of data types predefined in FB; you can also create user-defined data types called records. See Appendix B: Variables for more information.

Arrays
An array is a collection of variables which all share the same name and same data type. Each variable in the collection is called an element of the array; your program distinguishes one element from another by means of subscripts, which are numbers in parentheses following the array’s name. For example, if  is the name of an array, then represents one element of the array, and  represents a different element of the array.

The example above illustrates a one-dimensional array. In a two-dimensional array, each element is represented by a unique ordered pair of subscripts. If  is the name of a two- dimensional array, then  represents an element of the array, and represents a different element of the array. An array can have more than two dimensions; in fact, it can have up to 255. You use the statement to declare how many dimensions a given array has, and to specify the maximum values that can be assigned to each subscript.

The minimum value that can be assigned to a subscript is always 0.

Conventions Used in this Manual
In the syntax descriptions that appear in the remainder of this manual, the following conventions apply:

[ ] { } | …
 * Items in  represent placeholders which should be replaced as indicated in the description;
 * Items in  represent literal text that you should enter exactly as shown;
 * Items in  represent literal text that you should usually enter exactly as shown; however, the following characters should not be entered, but have special meanings explained below:
 * Items enclosed in square brackets [ ] are optional;
 * Items separated by vertical bars | and enclosed by curly brackets { } represent a list from which one item should be chosen;
 * Items separated by vertical bars | and enclosed by square brackets [ ] represent a list from which one or zero items should be chosen;
 * An elipsis (…) indicates that the preceding item may be repeated an indefinite number of times.

Example: Consider the following syntax description template: bob [, {bill | ron [, rick]}] This template matches each of the following: bob bob, bill bob, ron bob, ron, rick