%************************************************ \chapter{The Syntax of \glsentrytext{minizinc}}\label{ch:minizinc-grammar} %************************************************ \noindent{}\minizinc\ \autocite{nethercote-2007-minizinc} is a solver-independent \gls{cml} that is used as the leading \gls{cml} throughout this thesis. This chapter offers a formal specification of the grammar of the current version \minizinc{} language, corresponding with \minizinc{} version 2.5.5. For the convenience of the reader the grammar has been split into several parts. \Cref{sec:mzn-grammar-items} shows the syntax for the top-level structure of a \minizinc{} model. \Cref{sec:mzn-grammar-typeinst} shows the syntax of type expressions, used for declarations and return types of functions. \Cref{sec:mzn-grammar-expressions} shows the syntax of \minizinc{}'s expressions. Finally, \Cref{sec:mzn-grammar-misc} contains the rules for identifiers and \glspl{annotation}. \section{Items} \label{sec:mzn-grammar-items} \begin{grammar} % A MiniZinc model ::= [ ";" ... ] % Items ::= \alt \alt \alt \alt \alt \alt \alt \alt \alt \alt ::= ":" % Include items ::= "include" % Variable declaration items ::= [ "=" ] % Enum items ::= "enum" [ "=" ] ::= \alt "++" ::= "{" "," ... "}" \alt "(" ")" % Assign items ::= "=" % Constraint items ::= "constraint" % Solve item ::= "solve" "satisfy" \alt "solve" "minimize" \alt "solve" "maximize" % Output items ::= "output" % Annotation items ::= "annotation" % Predicate, test and function items ::= "predicate" ::= "test" ::= "function" ":" ::= [ "=" ] ::= [ ( "," ... ) ] \end{grammar} \section{Type Instance Expressions} \label{sec:mzn-grammar-typeinst} \begin{grammar} % Type-inst expressions ::= \alt ::= ::= "var" \alt "par" \alt ::= "opt" \alt ::= "set" "of" \alt ::= "bool" \alt "int" \alt "float" \alt "string" ::= \alt \alt \alt "ann" \alt \{ "," ... \} \alt ".." % % Type-inst variables ::= \(regexp\left(\texttt{\$[A-Za-z][A-Za-z0-9\_]*}\right)\) % Array type-inst expressions ::= "array" [ "," ... ] "of" \alt "list" "of" \end{grammar} \section{Expressions} \label{sec:mzn-grammar-expressions} \begin{grammar} % Expressions ::= ::= ::= [ ] ::= \alt "(" ")" \alt \alt "_" \alt \alt \alt \alt \alt \alt \alt \alt \alt \alt \alt \alt \alt \alt ::= \alt % Numeric expressions ::= ::= ::= [ ] ::= \alt "(" ")" \alt \alt \alt \alt \alt \alt \alt % Built-in operators ::= \alt ::= \alt ‘ ::= "<->" \alt "->" \alt "<-" \alt "\\/" \alt "xor" \alt "/\\" \alt "<" \alt ">" \alt "<=" \alt ">=" \alt "==" \alt "=" \alt "!=" \alt "in" \alt "subset" \alt "superset" \alt "union" \alt "diff" \alt "symdiff" \alt ".." \alt "intersect" \alt "++" \alt ::= "not" \alt % Built-in numeric operators ::= \alt ‘ ::= "+" \alt "-" \alt "*" \alt "/" \alt "div" \alt "mod" \alt "^" ::= "+" \alt "-" % Boolean literals ::= "false" \alt "true" % Integer literals ::= \(regexp\left(\texttt{\textbackslash{}d+}\right)\) \alt \(regexp\left(\texttt{0x\textbackslash{}x+}\right)\) \alt \(regexp\left(\texttt{0o\textbackslash{}O+}\right)\) % Float literals ::= \(regexp\left(\verb=\d+\.\d+=\right)\) \alt \(regexp\left(\verb=\d+\.\d+[Ee][-+]?\d+=\right)\) \alt \(regexp\left(\verb=\d+[Ee][-+]?\d+=\right)\) \alt \(regexp\left(\verb=0[xX](\x*\.\x+|\x+\.)([pP][+-]?\d+)=\right)\) \alt \(regexp\left(\verb=(0[xX]\x+[pP][+-]?\d+)=\right)\) % String literals ::= \(regexp\left(\verb=([^"\n\] | \[^\n(])*=\right)\) ::= \" \" \alt \" "\\(" ::= ")" \" \alt ")" "\\(" % Set literals ::= "{" [ "," ... ] "}" % Set comprehensions ::= "{" "\alt" "}" ::= [ "where" ] "," ... ::= "," ... "in" % Array literals ::= "[" [ "," ... ] "]" % 2D Array literals ::= "[\alt" [ ( "," ...) "\alt" ... ] "\alt]" % Array comprehensions ::= "[" "\alt" "]" % Array access ::= "[" "," ... "]" % Annotation literals ::= [ "(" "," ... ")" ] % If-then-else expressions ::= "if" "then" [ "elseif" "then" ]* "else" "endif" % Call expressions ::= [ "(" "," ... ")" ] % Let expressions ::= "let" "{" ";" ... "}" "in" ::= \alt % Generator call expressions ::= "(" ")" "(" ")" \end{grammar} \section{Identifiers and Annotations} \label{sec:mzn-grammar-misc} \begin{grammar} % % Miscellaneous % Identifiers ::= \(regexp\left(\texttt{[A-Za-z][A-Za-z0-9\_]*}\right)\) \alt \(regexp\left(\verb|'[^'\xa\xd\x0]*'|\right)\) % Identifiers and quoted operators ::= \alt ’’ % Annotations ::= [ "::" ]* ::= ::= "::" \end{grammar}