Appendix B — OPAL Language Syntax

This appendix reproduces the compact grammar summary of the OPAL input language. Words in italic in the legacy appendix denote syntactic entities, while monospaced tokens must be entered literally.

B.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_ _attribute-list_ or _label_ : _keyword_ _attribute-list_
attribute _attribute-name_, _attribute-name_ = _attribute-value_, or _attribute-name_ := _attribute-value_

The distinction between = and := is semantic as well as syntactic:

  • = evaluates the expression immediately.
  • := stores the expression for later evaluation.

An attribute value may be any of the parser categories used in the original appendix:

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

B.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 recursive exponentiation _real-factor_ ^ _real-primary_
real-primary real literal, symbolic constant, #, real name, array lookup, object attribute lookup, table reference, function call, or parenthesized expression

Built-in scalar functions listed by the legacy appendix are:

  • 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_

B.3 Real Variables and Constants

Entity Form
real-prefix empty, REAL, CONST, or REAL CONST
real-definition _real-prefix_ _real-name_ = _real-expression_ or := variant
symbolic-constant PI, TWOPI, DEGRAD, RADDEG, E, EMASS, PMASS, HMMASS, UMASS, CMASS, MMASS, DMASS, XEMASS, CLIGHT

The original appendix also lists _real-name_, _object-name_, _table-name_, and _column-name_ as identifiers.

B.4 Logical Expressions and Variables

Logical expressions are built from relations combined with && and ||. The relation grammar allows:

  • _logical-name_
  • 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.

B.5 String Expressions and Constants

String expressions may be:

  • a literal string
  • an identifier interpreted as a string
  • a concatenation _string-expression_ & _string_

String definitions use the prefix STRING:

  • STRING name = expression
  • STRING name := expression

B.6 Real Array Expressions and Definitions

The legacy appendix distinguishes scalar and array grammars explicitly. Array expressions mirror scalar arithmetic:

  • 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_ : REAL VECTOR
  • _array-definition_ : _array-prefix_ _array-name_ = _array-expression_
  • _array-definition_ : _array-prefix_ _array-name_ := _array-expression_

B.7 Constraints

Constraints are first-class attribute values in the grammar. The appendix gives exactly:

  • _constraint_ : _array-expression_ _constraint-operator_ _array-expression_

with allowed operators:

  • ==
  • <
  • >

This is the form used by optimization-related commands when comparing vector or sampled quantities.

B.8 Variable References

The variable-reference grammar in the appendix is intentionally small:

  • _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.

B.9 Token Lists and Regular Expressions

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

Token lists:

  • _token-list_ : _anything-except-comma_
  • _token-list-array_ : _token-list_
  • _token-list-array_ : _token-list-array_ , _token-list_

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.