26  Appendix B — Input Language Syntax

This appendix summarizes OPALX input syntax. Italic names denote syntactic entities, while monospaced tokens must be entered literally. Attribute-specific restrictions belong to the corresponding command reference.

26.1 Statements

Entity Form
comment // ... or /* ... */
identifier [A-Za-z][A-Za-z0-9_.]*
integer [0-9]+
string single-quoted or double-quoted text
command _keyword_; or _keyword_, _attribute-list_;, optionally preceded by _label_ :
attribute-list One attribute followed by zero or more , _attribute_ entries.
attribute _attribute-name_, _attribute-name_ = _attribute-value_, or _attribute-name_ := _attribute-value_

Unquoted identifiers and keywords are case-insensitive: the lexer normalizes them to upper case. Quoted text preserves its case. A hyphen is not part of an unquoted identifier.

For real and logical expression-valued attributes, = evaluates immediately, whereas := retains an expression for later evaluation. This distinction is not universal: string values are parsed and stored immediately with either operator. Use = for real constant definitions; := is not supported there.

Structured statements and macro definitions/calls have additional forms; see Control Statements.

The accepted value category depends on the attribute’s registered type. Categories used by supported input interfaces include:

  • string expression
  • logical expression
  • real expression
  • array expression
  • variable reference
  • place
  • range
  • token list
  • token-list array
  • regular expression

26.2 Real Expressions

Entity Form
real-expression _real-term_, unary +/- _real-term_, or recursive + / - combinations
real-term _real-factor_ or recursive * / / combinations
real-factor _real-primary_ or _real-primary_ ^ _real-primary_
real-primary real literal, symbolic constant, # inside a TABLE generator, real name, array lookup, object attribute lookup, table reference, function call, or parenthesized expression

A factor accepts at most one exponentiation operator. Write (a^b)^c or a^(b^c) when grouping powers; an unparenthesized a^b^c is not accepted.

Built-in scalar functions include:

  • RANF, GAUSS
  • ABS, TRUNC, ROUND, FLOOR, CEIL, SIGN
  • SQRT, LOG, EXP
  • SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2
  • MAX, MIN, MOD, POW

Functions of arrays are:

  • VMIN
  • VMAX
  • VRMS
  • VABSMAX

The grammar also allows:

  • _array_[ _index_ ]
  • _object-name_ -> _real-attribute_
  • _object-name_ -> _array-attribute_[ _index_ ]
  • _table-reference_

26.3 Real Variables and Constants

Entity Form
real-prefix REAL for variables; CONST, CONSTANT, REAL CONST, or REAL CONSTANT for constants.
real-definition _real-prefix_ _real-name_ = _real-expression_;. Variables also permit :=; real constants use =.
symbolic-constant PI, TWOPI, DEGRAD, RADDEG, E, EMASS, PMASS, HMMASS, UMASS, CMASS, MUMASS, DMASS, XEMASS, CLIGHT, H2PMASS, ALPHAMASS, AMU, OPALVERSION, RANK

An existing real variable can be reassigned without repeating its type prefix. A new bare-name assignment does not declare a variable; use REAL when introducing one.

Unquoted real names, object names, table names, and column names follow the identifier syntax defined above.

26.4 Logical Expressions and Variables

Logical expressions combine relations using && and ||. Relations bind first, then &&, then ||; parentheses group logical expressions. Both operands are evaluated, so C-style short-circuit behavior must not be assumed.

The relation grammar allows:

  • _logical-name_
  • ( _logical-expression_ )
  • TRUE
  • FALSE
  • _real-expression_ _relation-operator_ _real-expression_

The relation operators are:

  • ==
  • !=
  • <
  • >
  • >=
  • <=

Logical variables use the prefixes:

  • BOOL
  • BOOL CONST

and the same = versus := distinction as for reals.

26.5 String Expressions and Constants

String expressions may be:

  • a literal string
  • an existing string-valued name or a known object name; arbitrary unquoted text is not a general string literal
  • a concatenation _string-expression_ & _string_

String definitions use the prefix STRING:

  • STRING name = expression
  • STRING name := expression

String parsing stores the value immediately for both forms; := does not create a deferred string expression.

26.6 Real Array Expressions and Definitions

Array expressions support the following arithmetic operations:

  • unary + and -
  • binary +, -, *, /
  • exponentiation
  • parentheses

The array primaries are:

  • { _array-literal_ }
  • _array-reference_
  • _real-function_( _array-expression_ )
  • ( _array-expression_ )

The array literal grammar is recursive:

  • _array-literal_ : _real-expression_
  • _array-literal_ : _array-literal_ , _real-expression_

Array references may be:

  • _array-name_
  • _object-name_ -> _array-attribute_

Real array definitions use:

  • _array-prefix_ : VECTOR or REAL VECTOR
  • _array-definition_ : _array-prefix_ _array-name_ = _array-expression_
  • _array-definition_ : _array-prefix_ _array-name_ := _array-expression_

VECTOR and REAL VECTOR declare a global real array; ARRAY is not a declaration keyword. Braces form array values, including array-valued command attributes. For example:

REAL VECTOR V = {1, 2, 3};
VECTOR W := {1, 2, 3};

The exponentiation grouping rule above also applies to real arrays.

26.7 Variable References

A variable reference names a real variable or an object attribute:

  • _variable-reference_ : _real-name_
  • _variable-reference_ : _object-name_ -> _attribute-name_

This is the basic hook that lets later statements reuse parser-visible values and object attributes.

26.8 Token Lists and Regular Expressions

The final grammar sections define parser tokens that are not scalar numbers.

Token lists:

  • A token list ends at a top-level comma, semicolon or closing delimiter. Balanced nested (), [] and {} remain part of the list.
  • _token-list-array_ : _token-list_
  • _token-list-array_ : { _token-list_, ... } for multiple token lists

Regular expressions:

  • _regular-expression_ : " UNIX-regular-expression "

These forms appear mostly in higher-level command attributes and parser-side matching constructs rather than in beam-dynamics expressions.