132 Syntactic Grammar

Note that the following grammar requires name resolution to disambiguate certain cases. For example, the expression a.b.c might involve namespace names, type names, attribute names, variable names or function names. A dotted call such as a.b(c) may be a qualified function call, a procedure call, or a receiver-call path segment; the function-call and procedure chapters give the resolution rules.

A call-shaped expression such as Point(1, 2) may also resolve as the positional shorthand for a nominal constructor when Point names a concrete nominal type. The named-field form Point { x = 1, y = 2 } is the preferred constructor syntax.

The expression grammar exposes delimiter forms syntactically. Later name and type resolution classifies f(x) as a function call, Point(1, 2) as a positional constructor, Point { x = 1, y = 2 } as a named-field constructor, and Box<Integer> { value = 1 } as a generic constructor application. Postfix square syntax is the source shape for indexing, but an implementation may reject it until the relevant list, map, or indexable-value semantics are available in that context. A primary square expression after a dot, as in items.[predicate], is the filter path segment.

The grammar is presented in a natural mathematical style and is not intended to be directly consumed by an LL parser.

Grammar conventions

The grammar is written in an extended BNF notation that follows ISO/IEC 14977 (the ISO standard for EBNF), with the sole exception that ε is used to denote the empty production where this simplifies the denotational semantics.

Non-terminals are written in CamelCase. Terminals appear as quoted symbols or lexical categories. The following conventions apply:

  • ε denotes the empty production, meaning that the non-terminal may derive the empty sequence of tokens.
  • X, Y denotes concatenation of grammar symbols.
  • X | Y denotes alternatives.
  • [ X ] denotes optionality.
  • { X } means repetition (zero or more).

The syntactic grammar is split into the following chapters:

  • Source files and declarations
  • Statements
  • Expressions
  • Type definition grammar