lwgray / think

MIT License
0 stars 1 forks source link

Parser fails to recognize floating-point numbers in ThinkPy code #5

Closed lwgray closed 1 week ago

lwgray commented 1 week ago

Description

The ThinkPy parser currently fails to properly recognize floating-point numbers in code, throwing a syntax error when encountering numbers like 10.5. This affects basic arithmetic operations and variable assignments using decimal numbers.

Steps to Reproduce

  1. Create a ThinkPy program with floating-point numbers:
    
    %%thinkpy --explain
    objective "Test float operations"

task "FloatMath" { step "Basic arithmetic" { a = 10.5 b = 3.0 result = a / b print(result) } }

run "FloatMath"


2. Run the program

### Current Behavior
The parser throws a syntax error:

ThinkPy Error: Syntax error at token FLOAT Line: 5 Column: 15 Context: Near token: '0.5'



### Expected Behavior
The parser should recognize `10.5` and `3.0` as valid floating-point numbers and execute the arithmetic operations successfully.

### Root Cause
The lexer token ordering causes the NUMBER token to consume the "10" portion before the FLOAT token can properly match the entire "10.5" number. The FLOAT token definition needs to be placed before the NUMBER token in the lexer rules to ensure proper pattern matching.

### Environment
- Python Version: 3.13
- ThinkPy Parser Version: 1.0