Skip to content

[General]: Operator precedence is unspecified, so BSR and IDIV expressions have two readings #109

Open

Description

@shuklaayush

Problem

The expression grammar in the language manual (ISA_LRM, "Expressions") is

expression = atomic-expression
           | unary-operator expression
           | expression binary-operator expression
           | …

Neither the manual nor reading-specs.md gives a precedence or associativity for
the operators. The specification contains expressions whose value depends on them:

  • BSR.xml line 140: let highest_bit := operand_size - 1 - Count_Leading_Zero_Bits(src);

    With operand_size = 32 and src = 1, Count_Leading_Zero_Bits(src) is 31. Grouping
    to the left gives (32 - 1) - 31 = 0, the index of the highest set bit. Grouping to the
    right gives 32 - (1 - 31) = 62.

  • IDIV.xml line 127: let max := 2 ** (operand_size - 1) - 1;

    With operand_size = 32: if ** binds tighter than -, this is
    2**31 - 1 = 2147483647, the largest 32-bit signed value; if - binds tighter, it is
    2 ** 30 = 1073741824.

Proposed fix

State the expression grammar in levels, saying which operators may be combined without
parentheses and how each level groups. For reference, the isa-tools parser
(isa_parser.mly) uses these rules:

  • and, or, xor, and then and or else cannot be mixed without parentheses;
  • comparisons do not associate;
  • + and - group to the left, and ++ cannot be mixed with them;
  • *, / and % cannot be mixed with each other;
  • the operands of **, and the right operand of << and >>, are primary expressions.

AI disclosure

Assisted-by: Claude

Claude assisted with source analysis, the proposed correction and drafting this report.
Reviewed with assistance from Codex.

Activity

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions