Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop Body Termination in ThinkPy Parser #35

Open
lwgray opened this issue Nov 23, 2024 · 0 comments
Open

Loop Body Termination in ThinkPy Parser #35

lwgray opened this issue Nov 23, 2024 · 0 comments
Assignees
Labels

Comments

@lwgray
Copy link
Owner

lwgray commented Nov 23, 2024

Issue Description

The current ThinkPy parser incorrectly includes statements outside of loop bodies within the loop's AST. This causes premature loop termination when executing statements that should be outside the loop.

Example of the Problem

# Original Code
objective "Test list operations"
task "Lists":
    step "Process": 
        items = []
        for i in range(3): 
            items = items + [i]
        print(items)
        print(items[1])
run "Lists"

Current Parser Behavior

The parser incorrectly includes both print statements in the loop's body in the AST:

'body': [
    {'type': 'assignment', ...},
    {'type': 'function_call', 'name': 'print', 'arguments': ['items']},
    {'type': 'function_call', 'name': 'print', 'arguments': [{'type': 'index'...}]}
]

Constraints

The solution must:

  1. Clearly define loop body boundaries
  2. Not require additional keywords (like 'end')
  3. Not use curly braces or parentheses
  4. Not use semicolons
  5. Not rely on specific keywords after the loop
  6. Not require additional step definitions
  7. Keep the language simple and Pythonic
  8. Support multiple statements within loop bodies

Desired Solution

  1. Move to a indent/dedent syntax

Temporary Hack

  1. Use END to indicate the end of a loop body
# Original Code
objective "Test list operations"
task "Lists":
    step "Process": 
        items = []
        for i in range(3):
           items = items + [I]
        end
        print(items)
        print(items[1])
run "Lists"

Questions to Consider

  1. How can we unambiguously determine where a loop body ends?
  2. What parsing strategies could maintain simplicity while providing clear boundaries?
  3. Are there existing language designs that solve this elegantly without the above constraints?

Impact

This issue affects:

  • Loop execution
  • Program flow control
  • Statement grouping
  • AST generation accuracy

Labels

  • bug
  • parser
  • needs-discussion
  • syntax-design

Priority

High - This affects basic program flow control and execution accuracy.

@lwgray lwgray added bug Something isn't working parser complexity : Master labels Nov 23, 2024
@lwgray lwgray self-assigned this Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant