Skip to content

No Operator Precedence for Multiplication and Division #8

Description

@SAMBA8695

Bug Report: No Operator Precedence for Multiplication and Division

Description

The lexer supports multiplication (*) and division (/) tokens, but the parser does not implement operator precedence.

All binary operators are currently parsed with the same precedence, causing expressions involving * and / to be parsed incorrectly.

Example Input

let x = 2 + 3 * 4;

Correct Interpretation

2 + (3 * 4)

Current Interpretation

(2 + 3) * 4

Current Behavior

  • Lexer produces TOKEN_STAR and TOKEN_SLASH
  • Parser treats all operators equally
  • Operator precedence rules are not applied
  • Expression evaluation order is incorrect

Expected Behavior

  • * and / should have higher precedence than + and -
  • Expressions should follow standard arithmetic precedence
  • Precedence should work correctly with parentheses
  • Nested expressions should be parsed correctly

Suggested Direction

  • Implement a precedence-aware expression parser
  • Possible approaches:
    • Recursive descent with parse_term() / parse_factor()
    • Precedence climbing parser
  • Ensure compatibility with existing + and - handling

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