Skip to content

Conversation

@DSun91
Copy link

@DSun91 DSun91 commented Aug 5, 2024

This pull request introduces support for While and For loops in the Slang language parser and Abstract Syntax Tree (AST).

Key changes:

  1. AST Nodes:

    • Added WhileLoop and ForLoop dataclasses to represent loop constructs in the AST.
    • Both classes extend the Statement class and include fields for conditions and contained statements.
  2. Parser Grammar:

    • Updated the grammar with rules for while and for loops.
    • The while loop syntax is: WHILE (condition) { statements }
    • The for loop syntax is: FOR (variable : start -> end, interval) { statements }
  3. Lexer:

    • Added WHILE and FOR tokens to the lexer.
    • Added COLS: ':' and ARR: '->' operators to the lexer.
  4. Node Factories:

    • Implemented node factories for WhileLoop and ForLoop to transform parse tree nodes into AST nodes.
    • The ForLoop factory handles optional interval parameter.
  5. Testing:

    • Added test case for the TEST_WORKSPACE to verify correct parsing and AST construction for the new loop constructs.
    • Parametrized tests to include the new test cases.

These changes are intented to enhance the Slang language's capabilities.
Please review the changes, particularly the grammar updates and node factory implementations, to ensure they align with the intended language design and coding standards.

- Implement WhileLoop and ForLoop dataclasses
- Add grammar rules for while and for loops
- Update lexer with WHILE and FOR tokens
- Implement node factories for WhileLoop and ForLoop
- Add test cases for new loop constructs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant