This chapter describes the fundamental syntax of the Fire language.
Fire is a block-structured language made up of statements and commands. It has most of the usual features associated with other scripting languages, together with an in-built set of commands to manipulate vector and raster graphic data.
It is important to note that Fire is an interpreted language, so there is no compilation necessary to run a program written in Fire. However, applications can be "compiled" for packaging and security purposes if required.
Each statement or command in the language is either an assignment or an instruction to do something.
An assignment is the means by which program variables are given values. It has the general form:
<ident> = <value>
where ident is a program identifier (the name of a variable) of a particular type. There are in-built data types, e.g. a numeric, a string, a point etc. There are also user-defined data types, analagous to classes in other languages. Identifiers are discussed in a later section.
Some examples of assignments are:
x = 10 ;# a numeric assignment p = (45,77,99) ;# a point assignment s = 'Title:' ;# a string assignment t = '3-Mar-1992 10:00' ;# a time assignment
A command is an instruction to the system to do something. It takes the form of a command name followed by a number of command parameters:
<command> { <params>, ... }
The command name should be separated from its parameters by one or more spaces or tabs, known as white space. Multiple parameters should be separated by commas.
The command name tells the system what to do, the parameters tell the system what to do it to.
Command parameters are categorized into positional parameters and keyword parameters. Positional parameters are the base parameters required by a command and must appear on the command line in a predefined order, although some commands do permit trailing positional parameters to be omitted. Their values depend on the requirements of a particular command, e.g. identifier names, numeric values, character strings, file names etc.
Consider these examples:
delete mywin
The command is wdelete, which deletes a Fire window. It takes one parameter, an identifier pointing to the window to be deleted.
highlight myarc, mycircle, myellipse
Here, the command is highlight, which highlights one or more graphic entities on the screen. It can take multiple parameters, the names of the entities to be highlighted. Here we have given it 3 parameters.
Keyword parameters for commands (also known as command switches) are optional and may appear in any order on the command line after the command itself, i.e. after, before or even between positional parameters. They provide the system with additional information about how to execute the command, or they may change command default values. Keyword parameters are differentiated from positional parameters by the fact that they begin with a - (dash) character.
In most cases, switches take the form of an assignment:
<keyword> = <value>
e.g.
walpha -col=green
which creates an alpha window and defines its color , thereby overriding the default.
Keyword values, like positional parameter values, depend on the requirements of the command they are associated with, although some keywords are common to many different commands.
Many keywords are defined as boolean, i.e. they provide a true or false value to the system. Boolean keyword values may be indicated in many ways. Consider the boolean keyword fix, often used to create a window which cannot be resized:
-fix -fix= -fix=on -fix=true
These are all valid methods of setting the boolean keyword value to true.
Conversely:
-no_fix -fix=0 -fix=off -fix=false
These are all valid ways of setting the value to false.</p>
There are no keyword parameters associated with assignment statements.
From now on the generic terms command or statement will be used to refer to both assignment statements and command statements with their associated parameters.
A command line is a language statement containing one or more commands to be executed. A command should be separated from other commands on the same command line by a semi-colon, e.g.
numeric x = sqrt(99); tell x
which declares and assigns a numeric identifier, then displays its value.
A command can be preceded or followed by any number of white space characters. Blank lines are ignored completely.
When a command begins with a # character, that command and all subsequent commands on the command line are treated as comments and ignored, e.g.
# Assignment of a variable numeric x = sqrt(99); tell x; # Print its value
As a general rule, with the exception of the separation between a command and its first parameter, and within quotes to define string contents, all other white space on a command line is ignored.
Multiple command lines may be concatenated into one line by terminating all but the last by a \ character, which effectively "escapes" the end-of-line character, e.g.
x = 3.5 ** 4 \ * sqrt(52)
is equivalent to
x = 3.5 ** 4 * sqrt(52)
A command line beginning with an equal sign, "=" will repeat the previous command line. However, starting a command with "=" anywhere else other than as the first character will be treated as an invalid command and will produce an error.
A command block is a sequence of related commands forming a logical block. For example a set of commands which has to be executed if a particular condition is true, or a set of commands which has to be repeatedly executed.
Such a command block is indicated by enclosure within special punctuation characters { and }, known as braces. Inherent with these are new line characters before and after each brace character, i.e.
if (x = 2) { x = 4; y = 7 }
is equivalent to
if (x = 2) ;{; x = 4; y = 7 ;};
Command blocks are discussed in depth in the section TODO Control Flow.
Sequences of commands can be stored in external text files and executed. Such files are known as macros. Memory-resident command sequences may also be created and are known as user-procedures or user-functions. Macros, procedures and functions are known collectively as command frames and may be passed parameters. They are discussed more fully in later sections.
String constants are literal text values. They are indicated within quotes, either single or double, e.g.
'The rain in Spain' "The rain in Spain"
Back quotes (graves) should not be used. They have a special meaning within the language.
When a quote character is required in a string, this can be achieved either by using the other enclosing quote character or by escaping the character within the string by use of a backslash character \.
string s = "Oh no it isn't" string s = 'Oh no it isn\'t'
A semi-colon within a string is not taken as an end-of-command character but as part of the string.
Because a backslash is the escape character, a backslash must itself be escaped if it is to be valid within a string.
'A \\ is a backslash'
will be interpreted as A \ is a backslash, but
'A \ is a backslash'
will be interpreted as A is a backslash.
This escaping mechanism can be used to indicate other special characters, e.g.
\n
New line character (line feed)
\r
Carriage return
\a
Alarm (bell)
\t
Tab character
Command names are predefined, but aliases may be defined by users. Before a command is executed, its name is checked against known aliases, and if a match is found the command name is replaced by the alias value, e.g.
alias fred='dir' fred *.cmd
This defines fred to be an alternative name for the command dir. Then whenever fred is found in a command context, the dir command will be executed. Aliases may be defined for any identifier name, not only commands. Refer to the later sections Aliases.
On the odd occasion, it is useful to bypass the alias facility. To achieve this, a command preceded by a backslash will not check for any aliases on that command line, e.g.
\fred
This will in fact produce an "invalid command" message because there is no system command fred.
In addition, there are identifiers known as stanzas which enable multiple commands to be treated as one. Parameters may be passed to stanzas. For block purposes, a stanza is treated as a single command even though it may represent multiple commands. Consult the section Stanzas for full details.
A command may also be evented, with the result that whenever it is called, a sequence of associated commands is executed before it or after it or both. Eventing, discussed in the section Command Events, may be suppressed for a particular command either by the setting the system identifier eventing to false, or by preceding the command with a % character.