feat: while and for loops support for parser, plus new ASTs, new tokens and fixes inside parser
This commit is contained in:
parent
f8b91d4da3
commit
423793903d
9 changed files with 341 additions and 35 deletions
34
src/utils/ast/ast_loop.h
Normal file
34
src/utils/ast/ast_loop.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef AST_LOOP_H
|
||||
#define AST_LOOP_H
|
||||
|
||||
#include "ast_base.h"
|
||||
|
||||
struct ast_loop
|
||||
{
|
||||
// Repeat body while condition is true
|
||||
struct ast *condition;
|
||||
struct ast *body;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the given AST node is a loop.
|
||||
*/
|
||||
bool ast_is_loop(struct ast *node);
|
||||
|
||||
/**
|
||||
* Retrieves the loop data from the given AST node.
|
||||
* Assumes that the node is of type AST_LOOP.
|
||||
*/
|
||||
struct ast_loop *ast_get_loop(struct ast *node);
|
||||
|
||||
/**
|
||||
* Creates a new AST node representing a loop.
|
||||
*/
|
||||
struct ast *ast_create_loop(struct ast* condition, struct ast* body);
|
||||
|
||||
/*
|
||||
* @brief: frees the given ast_loop and sets the pointer to NULL.
|
||||
*/
|
||||
void ast_free_loop(struct ast_loop *loop_node);
|
||||
|
||||
#endif /* ! AST_LOOP_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue