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

feat: Create new AST structures #73

Open
28 of 70 tasks
xmnlab opened this issue Aug 11, 2024 · 0 comments
Open
28 of 70 tasks

feat: Create new AST structures #73

xmnlab opened this issue Aug 11, 2024 · 0 comments

Comments

@xmnlab
Copy link
Contributor

xmnlab commented Aug 11, 2024

Here’s a comprehensive list of possible Abstract Syntax Tree (AST) node types that are generic and can be applied to various programming languages like Python, Rust, or JavaScript. Each node type is categorized as either a statement (Stmt) or an expression (Expr) where necessary.

1. Program Structure

2. Declarations

3. Expressions

4. Statements

  • AssignmentStatement - Assigns a value to a variable.
  • ExpressionStmt - A statement that evaluates an expression (common in JavaScript, Python).
  • ReturnStmt - Represents a return statement.
  • BreakStmt - Represents a break statement (used to exit loops).
  • ContinueStmt - Represents a continue statement (skips the rest of the loop iteration).
  • IfStmt - Represents an if statement.
  • ElseStmt - Represents an else statement (paired with IfStmt).
  • ElseIfStmt - Represents an else-if statement (used in Python, JavaScript).
  • MatchStmt - Represents a match or switch statement.
  • WhileStmt - Represents a while loop.
  • ForRangeStmt - Represents a for range loop.
  • ForCounterStmt - Represents a for counter loop.
  • ForEachStmt - Represents a for each loop.
  • DoWhileStmt - Represents a do-while loop.
  • ThrowStmt - Represents a throw statement (for exceptions). #100
  • TryStmt - Represents a try block. #101
  • CatchStmt - Represents a catch block. #102
  • FinallyStmt - Represents a finally block (used with try-catch). #103
  • AssertStmt - Represents an assert statement.
  • PassStmt - Represents a pass statement (no-op, common in Python).

5. Functionality

6. Control Flow

7. Error Handling

  • TryCatchStmt - A combined try-catch statement (sometimes considered separately as TryStmt and CatchStmt).
  • ThrowExpr - Represents a throw expression (for exceptions).
  • RaiseStmt - Represents a raise statement (specific to Python).

8. Types and Casting

9. Object-Oriented Constructs

  • NewExpr - Represents object instantiation (e.g., new in JavaScript).
  • MethodCallExpr - Represents a method call (e.g., obj.method()).
  • ThisExpr - Represents the current instance (e.g., this in JavaScript).
  • SuperExpr - Represents the superclass reference (e.g., super in Python).

10. Memory Management

  • AllocExpr - Represents memory allocation (e.g., malloc in C).
  • DeallocStmt - Represents memory deallocation (e.g., free in C).

11. Miscellaneous

  • CommentStmt - Represents a comment.
  • DocStringStmt - Represents a documentation string (common in Python).

12. Meta

  • MetaExpr - Represents meta-programming constructs (like macros in Rust).

These node types cover a wide range of constructs found in various programming languages. Depending on the language, some of these node types might be more specific, and their usage might vary. This list should give you a solid foundation to model AST nodes generically across different programming paradigms.


It is not clear yet what would be a better solution for handling stmt and expr classes/types.

some alternatives (examples):

  • expr.flows.IfExpr
  • expr.flows.If
  • flows.expr.If
  • flows.expr.IfExpr
  • flows.IfExpr
  • stmt.flows.If
  • stmt.flows.IfStmt
  • stmt.flows.If
  • flows.stmt.IfStmt
  • flows.stmt.If
  • flows.IfStmt
@xmnlab xmnlab pinned this issue Aug 20, 2024
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

No branches or pull requests

1 participant