Skip to content

flowc and the Python parser disagree on shift and bitwise operator precedence #995

Closed

Description

@godofecht

flowc and the Python parser disagree on binary operator precedence, so the same source can parse to different trees.

Python (src/flow/parser.py), loosest to tightest:
or, and, |, ^, &, ==/!=, </>/<=/>=/in, <</>>, +/-, *///%.

flowc (flowc_parse_binop_prec in compiler/src/parser.flow):
|| 1, && 2, & | ^ << >> all 3, == != 4, comparisons 5, + - 6, * / % 7.

Differences:

  1. Shifts. Python binds <</>> tighter than comparison and equality; flowc binds them looser. a << 2 < b is (a << 2) < b in Python and a << (2 < b) in flowc.
  2. |, ^, & share one level in flowc and associate left, so a | b ^ c is (a | b) ^ c in flowc and a | (b ^ c) in Python.

Both parse, so parse coverage cannot see this. It changes the meaning of the C that Stage-A emits. Suggested fix: give flowc the Python levels (| 3, ^ 4, & 5, equality 6, comparison 7, shifts 8, additive 9, multiplicative 10) and check compiler/src for expressions whose meaning would change before regenerating the bootstrap C.

Activity

  1. added 2 commits that reference this issue on Sep 29, 2026
    28c32e1
    605589d
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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions