From 25c23ae3789b527a3a0bbb70f762d23db6408a6e Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Mon, 8 Mar 2021 11:42:49 +1100 Subject: [PATCH] Add MiniZinc syntax specification in the appendix --- chapters/4_rewriting.tex | 41 +++-- chapters/A1_minizinc_grammar.tex | 274 +++++++++++++++++++++++++++++++ dekker_thesis.tex | 10 +- 3 files changed, 300 insertions(+), 25 deletions(-) create mode 100644 chapters/A1_minizinc_grammar.tex diff --git a/chapters/4_rewriting.tex b/chapters/4_rewriting.tex index 766d51a..de3c789 100644 --- a/chapters/4_rewriting.tex +++ b/chapters/4_rewriting.tex @@ -180,20 +180,19 @@ This section introduces the two sub-languages of \minizinc\ at the core of the new abstract machine model we have developed. MicroZinc (\microzinc) is a simplified subset of \minizinc\ that only contains -function declarations and a restricted expression language. \minizinc\ models -can be translated into \microzinc. NanoZinc (\nanozinc) is similar to -\flatzinc\ in that it contains only simple variable declarations and flat -constraints. However, while all function calls in \flatzinc\ need to be +function declarations and a restricted expression language. Models written in +different \cmls\ can be translated into \microzinc. NanoZinc (\nanozinc) is +similar to \flatzinc\ in that it contains only simple variable declarations and +flat constraints. However, while all function calls in \flatzinc\ need to be solver-level primitives, \nanozinc\ calls can refer to functions implemented in \microzinc. -The core of the syntax of \microzinc\ is defined in -\cref{fig:4-uzn-syntax}. We have omitted the definitions of -\syntax{} and \syntax{}, which you can assume to be the same -as in the definition of \minizinc. While we omit the typing rules here for -space reasons, we will assume that in well-typed \microzinc\ programs, the -conditions \syntax{} in if-then-else and where expressions have \pari\ -type. +The core of the syntax of \microzinc\ is defined in \cref{fig:4-uzn-syntax}. We +have omitted the definitions of \syntax{} and \syntax{}, which +you can assume to be the same as in the definition of \minizinc. While we omit +the typing rules here for space reasons, we will assume that in well-typed +\microzinc\ programs, the conditions \syntax{} in if-then-else and where +expressions have \pari\ type. \begin{figure} \begin{grammar} @@ -219,11 +218,11 @@ type. \newcommand{\sep}{\rhd} -A \nanozinc\ program, defined in \cref{fig:4-nzn-syntax}, is simply a list -of calls, where the result of each call is bound to either an identifier or the +A \nanozinc\ program, defined in \cref{fig:4-nzn-syntax}, is simply a list of +calls, where the result of each call is bound to either an identifier or the constant true. The \syntax{$\sep$ *} will be used to track dependent -constraints (this will be explained in detail in \cref{sec:4-nanozinc}, for -now you can assume it is empty). +constraints (this will be explained in detail in \cref{sec:4-nanozinc}, for now +you can assume it is empty). \begin{figure} \begin{grammar} @@ -270,9 +269,9 @@ The translation from \minizinc\ to \microzinc\ involves the following steps: \begin{mzn} predicate all_different(array[int] of var int: x) = - forall (i,j in 1..length(x) where i ::= [ ";" ... ] + + % 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{[0-9]+}\right)\) + \alt \(regexp\left(\texttt{0x[0-9A-Fa-f]+}\right)\) + \alt \(regexp\left(\texttt{0o[0-7]+}\right)\) + + % Float literals + ::= \(regexp\left(\verb=[0-9]+\.[0-9]+=\right)\) + \alt \(regexp\left(\verb=[0-9]+\.[0-9]+[Ee][-+]?[0-9]+=\right)\) + \alt \(regexp\left(\verb=[0-9]+[Ee][-+]?[0-9]+=\right)\) + \alt \(regexp\left(\verb=0[xX]([0-9a-fA-F]*"."[0-9a-fA-F]+|[0-9a-fA-F]+".")([pP][+-]?[0-9]+)=\right)\) + \alt \(regexp\left(\verb=(0[xX][0-9a-fA-F]+[pP][+-]?[0-9]+)=\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} diff --git a/dekker_thesis.tex b/dekker_thesis.tex index fa8ecc0..19a699a 100644 --- a/dekker_thesis.tex +++ b/dekker_thesis.tex @@ -33,9 +33,9 @@ Some ideas and figures included in this thesis have previously appeared in the following publication: \begin{refsection}[ownpubs] - \small - \nocite{*} % is local to to the enclosing refsection - \printbibliography[heading=none] + \small + \nocite{*} % is local to to the enclosing refsection + \printbibliography[heading=none] \end{refsection} \mainmatter{} @@ -46,8 +46,10 @@ following publication: \include{chapters/5_half_reif} \include{chapters/6_incremental} -\backmatter{} +\appendix{} +\include{chapters/A1_minizinc_grammar} +\backmatter{} \printbibliography{} % \tableofcontents{} % \addcontentsline{toc}{chapter}{Contents}