Skip to content

Commit

Permalink
Fix operator precedences for intersect and unary plus/minus. Update…
Browse files Browse the repository at this point in the history
… the grammar and spec to make sure they're consistent with the implemented parser.
  • Loading branch information
guidotack committed Nov 12, 2024
1 parent 670d77a commit 9c4250e
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 200 deletions.
1 change: 1 addition & 0 deletions changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Bug fixes:
- Fix defines_var annotation for cyclic definitions (:bugref:`863`).
- Fix assertion failures when using arrays as argument to bin packing constraints
(:bugref:`865`).
- Fix operator precedences for ``intersect`` and unary plus/minus.

.. _v2.8.7:

Expand Down
3 changes: 1 addition & 2 deletions docs/en/grammar.mzn
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@
| <tuple-ti-expr-tail>
| <record-ti-expr-tail>
| "ann"
| "{" <expr> "," ... "}"
| <num-expr> ".." <num-expr>
| <expr>

% Type-inst variables
<ti-variable-expr-tail> ::= $[A-Za-z$][A-Za-z0-9_]*
Expand Down
81 changes: 45 additions & 36 deletions docs/en/spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1447,53 +1447,57 @@ Note that the last entry in the table, :mzn:`^-1`, is a combination of the binar
=============================== ====== ======
Symbol(s) Assoc. Prec.
=============================== ====== ======
:mzn:`<->` left 1200
:mzn:`<->` left 1600

:mzn:`->` left 1100
:mzn:`<-` left 1100
:mzn:`->` left 1500
:mzn:`<-` left 1500

``\/`` left 1000
:mzn:`xor` left 1000
``\/`` left 1400
:mzn:`xor` left 1400

``/\`` left 900
``/\`` left 1300

:mzn:`<` none 800
:mzn:`>` none 800
:mzn:`<=` none 800
:mzn:`>=` none 800
:mzn:`==`,
:mzn:`=` none 800
:mzn:`!=` none 800

:mzn:`in` none 700
:mzn:`subset` none 700
:mzn:`superset` none 700
:mzn:`<` none 1200
:mzn:`>` none 1200
:mzn:`<=` none 1200
:mzn:`>=` none 1200

:mzn:`==` none 1100
:mzn:`=` none 1100
:mzn:`!=` none 1100

:mzn:`union` left 600
:mzn:`diff` left 600
:mzn:`symdiff` left 600
:mzn:`in` none 1000
:mzn:`subset` none 1000
:mzn:`superset` none 1000

:mzn:`union` left 900
:mzn:`diff` left 900
:mzn:`symdiff` left 900

:mzn:`intersect` left 800

:mzn:`..` none 700
:mzn:`<..` none 700
:mzn:`..<` none 700
:mzn:`<..<` none 700

:mzn:`..` none 500
:mzn:`<..` none 500
:mzn:`..<` none 500
:mzn:`<..<` none 500
:mzn:`+` left 600
:mzn:`-` left 600

:mzn:`+` left 400
:mzn:`-` left 400
:mzn:`*` left 500
:mzn:`div` left 500
:mzn:`mod` left 500
:mzn:`/` left 500

:mzn:`^` left 400

:mzn:`*` left 300
:mzn:`div` left 300
:mzn:`mod` left 300
:mzn:`/` left 300
:mzn:`intersect` left 300
:mzn:`++` right 300

:mzn:`^` left 200

:mzn:`++` right 100
:mzn:`default` left 200

:mzn:`default` left 70
````` :mzndef:`<ident>` ````` left 100

````` :mzndef:`<ident>` ````` left 50
:mzn:`::` left 0
=============================== ====== ======


Expand All @@ -1508,6 +1512,11 @@ This is a static error if the identifier is not the name of a binary
function or predicate.

The unary operators are: :mzn:`+`, :mzn:`-` and :mzn:`not`.
Unary :mzn:`+` and :mzn:`-` have the same precedence as the binary
multiplication operator :mzn:`*`. The logic :mzn:`not` operator
has precedence 350, i.e., it binds more tightly than all other
Boolean and numeric operators.

User-defined unary operators are not possible.

As :ref:`spec-Identifiers` explains, any built-in operator can be used as
Expand Down
2 changes: 1 addition & 1 deletion lib/cached/md5_cached.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(lexer_lxx_md5_cached "1fd3518993d57146c38066eda73e9506")
set(parser_yxx_md5_cached "081f1fce960fc4a2d7eaa9dc1f363092")
set(parser_yxx_md5_cached "6762414c9408775ded333ad703b75b77")
set(regex_lexer_lxx_md5_cached "8906a52bfa0c5ae26354cb272348e656")
set(regex_parser_yxx_md5_cached "68ec070becef5e161c3b97d085b0810e")
Loading

0 comments on commit 9c4250e

Please sign in to comment.