Skip to content

mdl: operator precedence differs from Vensim, breaking :NOT: comparisons #914

Open

Description

@bpowers

The MDL parser's operator precedence does not match Vensim's, so :NOT: Time > 5 evaluates as (:NOT: Time) > 5 instead of Vensim's :NOT: (Time > 5).
The arithmetic and :AND: levels are wrong too, but that is hidden: the importer writes each equation out as flat text, and the XMILE parser re-reads it with the right grouping.
The :NOT: case cannot be hidden that way, because XMILE also binds not tighter than a comparison (spec section 3.3.1).

Example

not scalar = IF THEN ELSE(:NOT: Time > 5, 0, 1)

Vensim's run (test/test-models/tests/subscripted_logicals/output.tab) differs from ours on not_scalar, not_array and not_and_or; every other series in that model matches.

The hidden half, from the parser code: 1 + 2 > 2 parses as 1 + (2 > 2), and 2 > 1 :AND: 0 as 2 > (1 :AND: 0).

Why it matters

Any model with :NOT: in front of a comparison gets wrong numbers, silently.
The hidden half is a trap: the importer cannot add the parentheses it should (doing so keeps the wrong grouping and breaks C-LEARN against Ref.vdf), and any other code reading the MDL syntax tree sees the wrong grouping.

Fix

Reorder the MDL parser to Vensim's levels, lowest first: :OR:, :AND:, :NOT:, = <>, < > <= >=, + -, * /, unary + -, ^.
:NOT: needs its own level instead of sharing one with unary minus.
Then have xmile_compat parenthesize by precedence (writing not (time > 5)), widen the writer property test to all operators, and check C-LEARN still matches Ref.vdf.
The ground truth shows only that :NOT: binds looser than a comparison; the rest of this order is unverified against Vensim's documentation.

Pointers

  • src/simlin-engine/src/mdl/parser.rs: parse_add_sub through parse_power
  • src/simlin-engine/src/mdl/xmile_compat.rs: the note on why it does not parenthesize by precedence
  • src/simlin-engine/src/mdl/writer_proptest.rs: expr0_strategy, kept to arithmetic because of this
  • src/simlin-engine/tests/integration/mdl_vensim_truth.rs: the subscripted_logicals entry comes off its list once fixed

Activity

  1. changed the title [-]engine: MDL parser's binary operator precedence is inverted vs Vensim, masked by xmile_compat's precedence-free emission[/-] [+]mdl: operator precedence differs from Vensim, breaking :NOT: comparisons[/+] on Oct 12, 2026
  2. added
    engine
    compat
    bug
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompatengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions