para
The para command gives one or more names a numeric value, which later commands read as %name or inside [ ].
Syntax
para <name> <value> { <name> <value> } ;
parameter <name> <value> { <name> <value> } ;
name is a parameter name. value is a number, a %name or a [expr]. The ; after the last pair is required. parameter is the same command (JAMES_COMMAND_ALIASES in include/james/tables.h).
What it does
James stores each value under its name. A later %name takes the stored value, and a [expr] can compute from it. Writing para for a name again replaces the old value, whatever the name held before. para name(i,j) value assigns one element of an array that array declared.
When James applies it
By the preprocessor, when it is read, and before any command that follows is parsed. It is legal in any phase: Control, Part or Merge.
Rules James adds
- A
parainside the branch of anifthat is not taken never runs, because James never reads that branch. - A name compares in full and without regard to case. A
-is part of a name, so%a-1is one name; write%a - 1with spaces to subtract. - A value that fails to evaluate stores NaN for that one name and James reads the rest of the pairs.
- A purely numeric name, as in
para 1 5;, is an error. - An array element is assigned with the same command, and James evaluates the subscripts before it stores the value.
- The automatic parameters,
piamong them, cannot be assigned.
Diagnostics
- E0203: a value reads
%namebefore it has been given one, or reads an automatic James registers but has not set, such as%nextnode. - E0204: a value reads one of the automatic names James can never supply (
%node,%xboxminto%zboxmax). - E0205: the name is an automatic parameter or array, which no script may assign.
- E0213: a value is not finite.
- E0216: a name holds a reserved character.
- E0221: a
[expr]is not a well-formed expression. - E0104: the name is purely numeric, or a name or value is missing.
- E0206: an array element’s subscript is out of range.
- E0207: an array element has the wrong number of subscripts.
Example
The script tests/corpus/011-undefined-parameter-rejected/input.tg, which make test runs:
para y [%never_defined+1];
James prints this, which tests/corpus/011-undefined-parameter-rejected/expected.diag.txt holds:
input.tg:1:9: error [E0203]: parameter '%never_defined' is referenced before it is defined
james: 1 error, 0 warnings
James refuses the %never_defined in the expression, because it has no value yet. The prep dump stores NaN for y, and the run exits 1.
See also
- array: parameters that hold several values.
- def: parameters that are functions.
- painfo: print every parameter.
- Writing a script: the
%nameand[expr]forms.