Documentation

8.2 Source normalisation, lexing and names

Before expression parsing, nlmx converts physical control-stream lines into logical abbreviated-code lines. Semicolon comments are removed, trailing & joins a continuation to the following line, blank lines disappear and $ABBR REPLACE substitutions are applied.

The retained source-line index points to the first physical line of a joined statement. Error locations therefore identify the logical statement's origin, not every continuation fragment.

Case and replacements

Abbreviated code is normalised to uppercase. $ABBR REPLACE is token-aware at name boundaries, so replacing THETA(CL) does not unintentionally replace the same character sequence inside a longer identifier. Review replacements as part of the executable model: they alter code before parsing.

$ABBR PROTECT-style protected functions are represented by their P* equivalents where applicable. Protected functions deliberately cap or floor hazardous arguments; they are not numerically identical to unprotected functions at extremes.

Lexer responsibilities

The lexer recognises numeric literals, identifiers, array syntax, parentheses, commas, assignments, arithmetic operators and dotted Fortran logical/relational operators. It resolves common Fortran ambiguities before the recursive-descent parser applies precedence.

Names assigned anywhere in a block become local-variable slots. Local variables persist across records within a subject, matching Fortran SAVE-like behavior, and start at zero for each new subject. This persistence makes assignment order and conditional coverage important: a branch that does not assign a variable can leave its prior-record value intact.

Data-item aliases

Data references come from kept $INPUT items and their accepted names. Dropped items are not available to model code. If a header and $INPUT alias describe the same column, the compiled data item can accept those names according to the control-stream mapping established earlier.

Review implication

Compare normalised logical code, not only printed physical lines, when reproducing behavior. A semicolon can remove code, an & can merge tokens, and a replacement can change a parameter reference before evaluation.

Common mistakes

  • Expecting local variables to reset on every record.
  • Treating $ABBR REPLACE as documentation-only.
  • Referring to a $INPUT item marked DROP.

Checklist

  • Inspect comments, continuations and replacements.
  • Trace variables that are not assigned on every path.
  • Validate data-item names after $INPUT mapping.

Further reading

See expressions, control flow and Chapter 5's $INPUT mapping discussion.