Skip to content

Lexer bug causes infinite loop or parsing errors on subtraction (-) operations #1

Description

@AbhaySingh2477

Describe the bug

Any attempt to perform subtraction operations fails:

  1. 3 - 5 (with spaces around the minus operator) causes an infinite loop resulting in RangeError: Invalid array length.
  2. 3-5 or 3 -5 (without space after minus) gets parsed incorrectly as a negative number token ["3", "-5"] and throws Error: Unknown: ["3","-5"].

Steps to Reproduce

Run the calculator and input the following expressions:

echo "3 - 5" | node calculator.js # Causes RangeError: Invalid array length (infinite loop)
echo "3-5" | node calculator.js   # Causes Error: Unknown: ["3","-5"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions