\part{Appendix}
\appendix

\chapter{Syntax}

\begin{grammar}
<letter> = `A' | `B' | … | `Z' | `a' | `b' | … | `z' | `\_'.

<counting-digit> = `1' | `2' | `3' | `4' | `5' | `6' | `7' | `8' | `9'.

<decimal-digit> = `0' | <counting-digit>.

<hex-digit> = <decimal-digit> | `A' | `B' | … | `F' | `a' | `b' | … | `f'.

<binary-digit> = `0' | `1'.

<hex-character> = `\\x' <hex-digit> \{<hex-digit>\}.

<escaped-character> = `\\' \\
	(`n' | `t' | `f' | `r' | `v' | `\\' | `\textquotesingle' | `\textquotedbl' | `0').

<printable-character> = \enspace? a printable ASCII character\space?.

<character> = <printable-character> | <escaped-character> | <hex-character>.

<identifier> = <letter> \{<letter> | <decimal-digit>\}.

<identifier-definition> = <identifier> [`*'].

<trait-identifier> = `#' <identifier>.

<integer-literal> = `0' | <counting-digit> \{<decimal-digit>\}.

<word-literal> = <integer-literal> `u'
	\alt{} `0' (`X' | `x') <hex-digit> \{<hex-digit>\}
	\alt{} `0' (`B' | `b') <binary-digit> \{<binary-digit>\}.

<scale-factor> = (`e' | `E') [`+' | `-'] <decimal-digit> \{<decimal-digit>\}.

<real-literal> = <integer-literal> `.\@' <decimal-digit> \{<decimal-digit>\}
		[<scale-factor>]
	\alt{} <integer-literal> <scale-factor>.

<character-literal> = `\textquotesingle' <character> `\textquotesingle'.

<string-literal> = `\textquotedbl' \{<character>\} `\textquotedbl'.

<literal> = <integer-literal> | <word-literal> | <real-literal>
	\alt{} <string-literal> | <character-literal>
	\alt{} `true' | `false' | `nil'.

<trait> = <trait-identifier> `(' [<types>] `)'.

<cast> = `cast' `(' <expression> `:\@' <type> `)'.

<procedure-call> = <designator> `(' [<expressions>] `)'.

<relation-operator> = `=' | `<>' | `<' | `>' | `<=' | `>='.

<multiplication-operator> = `*' | `/' | `\%'.

<addition-operator> = `+' | `-'.

<shift-operator> = `<<' | `>>'.

<unary-operator> = `@' | `~' | `-'.

<selector> = `[' <expression> `]' | `.\@' <identifier> | `^'.

<case> = <expressions> `:\@' <statements>.

<designator> = <reference> <selector> | <identifier>.

<reference> = <literal>
	\alt{} <designator>
	\alt{} <trait>
	\alt{} <cast>
	\alt{} <procedure-call>
	\alt{} <record-constructor>
	\alt{} `(' <expression> `)'.

<record-constructor> = <identifier> `\{' [<field-initializer> \{`,' <field-initializer>\}] `\}'.

<field-initializer> = <identifier> `:' <expression>.

<factor> = <unary-operator> <factor> | <reference>.

<term> = <factor> \{<multiplication-operator> <factor>\}.

<simple-expression> = <term> \{<addition-operator> <term>\}.

<comparand> = <simple-expression> \{<shift-operator> <simple-expression>\}.

<relation> = <comparand> \{<relation-operator> <comparand>\}.

<operand> = <relation> \{`&' <relation>\}.

<expression> = <operand> \{(`or' | `xor') <operand>\}.

<expressions> = <expression> \{`,' <expression>\}.

<identifiers> = <identifier> \{`,' <identifier>\}.

<identifier-definitions> = <identifier-definition> \{`,' <identifier-definition>\}.

<types> = <type> \{`,' <type>\}.

<statements> = <statement> \{`;' <statement>\}.

<return-declaration> = [`:\@' `!\@' | `:\@' type].

<field> = <identifiers> `:\@' <type>.

<array-type> = `[' <expression> `]' <type>.

<pointer-type> = `^' <type>.

<record-type> = `record' [`(' <identifier> `)'] [<field> \{`;' <field>\}] `end'.

<enumeration-type> = `(' <identifiers> `)'.

<procedure-type> = `proc' <procedure-heading>.

<type> = <array-type>
	\alt{} <pointer-type>
	\alt{} <record-type>
	\alt{} <enumeration-type>
	\alt{} <procedure-type>
	\alt{} <identifier>.

<assignment> = <designator> `:=' <expression>.

<if-statement> = `if' <expression> `then' <statements> \\
    \{`elsif' <expression> `then' <statements>\} \\
	{[`else' <statements>]} `end'.

<while-statement> = `while' <expression> `do' <statements> \\
    \{`elsif' <expression> `do' <statements>\} `end'.

<defer-statement> = `defer' <statements> `end'.

<case-statement> = `case' <expression> `of' <case> \{`|' case\} \\
	{[`else' <statements>]} `end'.

<label-declaration> = `.\@' <identifier>.

<goto-statement> = `goto' <identifier>.

<statement> = <assignment> | <procedure-call> | <defer-statement>
	| <label-declaration> | <goto-statement> | <while-statement>
	| <if-statement> | <case-statement> | $\varepsilon{}$.

<statement-part> = [`begin' <statements>].

<constant-declaration> = <identifier-definition> `:=' <expression>.

<constant-part> = [`const' \{<constant-declaration>\}].

<variable-declaration> = <identifier-definitions> `:\@' <type> \\
	{[`:=' (<expression> | `extern')]}.

<variable-part> = [`var' \{<variable-declaration>\}].

<type-declaration> = <identifier-definition> `=' <type>.

<type-part> = [`type' \{<type-declaration>\}].

<import-declaration> = <identifier> \{`.\@' <identifier>\}.

<import-part> = [`import' \{import-declaration\}].

<parameter> = <identifiers> `:\@' <type>.

<procedure-heading> = `(' [<parameter> \{`;' <parameter>\}] `)' <return-declaration>.

<procedure-body> = <constant-part> <variable-part> <statement-part> [`return' <expression>] `end'.

<procedure-declaration> = `proc' <identifier-definition> <procedure-heading> \\
	(<procedure-body> | `extern').

<program> = <import-part>
    <constant-part> <type-part> <variable-part>
	\{<procedure-declaration>\}
	<statement-part> [`return' <expression>] `end' `.\@'.
\end{grammar}
