3 Syntax
Aprepro is in one of two states while it is processing an input file, either echoing or parsing. In
the echoing state, Aprepro echoes every character that it reads to the output file. If it reads the
character {, it enters the parsing state. In the parsing state, Aprepro reads characters from the
input file and identifies the characters as tokens which can be function names, variables, numbers,
operators, or delimiters. When Aprepro encounters the character }, it tries to interpret the tokens
as an algebraic, string, or conditional expression; if it is successful, it prints the value to the output
file; if it cannot evaluate the expression, it prints the message:
Aprepro: ERROR: parse error {filename}, line {line#}
to the terminal
1
prints the value 0 to the output file.
The rules that Aprepro uses when identifying functions, variables, numbers, operators, delimiters,
and expressions are described below:
Functions Function names are sequences of letters and digits and underscores ( ) that begin with
a letter. The function’s arguments are enclosed in parentheses.
For example, in the line atan2(a,1.0), atan2 is the function name, and a and 1.0 are the
arguments. See Chapter 6 for a list of the available functions and their arguments.
Variables A variable is a name that references a numeric or string value. A variable is defined
by giving it a name and assigning it a value. For example, the expression a = 1.0 defines
the variable a with the numeric value 1.0; the expression b= "A string" defines the variable
b with the value A string. Variable names are sequences of letters, digits, colons (:), and
underscores ( ) that begin with either a letter or an underscore. Variable names cannot match
any function name and they are case-sensitive, that is, abc de and AbC dE are two distinct
variable names. A few variables are predefined, these are listed in Chapter 5.
Any variable that is not defined is equal to 0. A warning message is output to the terminal if
an undefined variable is used, or if a previously defined variable is redefined. If the variable
name begins with an underscore, no warning is output when the variable is redefined.
2
.
Immutable Variables An immutable variable is a variable whose value cannot be changed. An
immutable variable name is follows the same rules as a regular variable except that the name
cannot begin with an underscore. Immutable variables are created inside an IMMUTABLE(ON)
block (See Section ??) or when Aprepro is executed with the --immutable or -X command
line options (See Chapter 2). If the value of an immutable variable is attempted to be modified,
an error message of the form: [Aprepro: (IMMUTABLE) Variable ’variable’ is immutable and
cannot be modified (file, line line#)] will be output to the standard error stream and the
expression containing the assignment to the immutable variable will return nothing.
Numbers Numbers can be integers like 1234, decimal numbers like 1.234, or in scientific notation
like 1.234E-26. All numbers are stored internally as floating point numbers.
Strings Strings are sequences of numbers, characters, and symbols that are delimited by either
single quotes (’this is a string’) or double quotes ("this is another string"). Strings
that are delimited by one type of quote can include the other type of quote. For example,
’This is a valid "string"’. Strings delimited by single quotes can span multiple lines;
1
Error messages are printed to standard error. On UNIX systems they can be redirected to a file using your shells
redirection syntax. See the man page for your shell for more information.
2
Warnings can be turned off with the -W or --warning option.
11