2025-01-06 03:00:01 +01:00
|
|
|
#ifndef STMT_H
|
|
|
|
#define STMT_H
|
|
|
|
|
|
|
|
#include "ast.h"
|
2025-01-06 04:53:15 +01:00
|
|
|
#include "lexer.h"
|
|
|
|
|
|
|
|
#define DEFAULT_STMTS_SIZE 512
|
|
|
|
|
2025-01-06 03:00:01 +01:00
|
|
|
typedef enum {
|
2025-01-06 04:53:15 +01:00
|
|
|
STMT_BLOCK,
|
|
|
|
STMT_CLASS,
|
|
|
|
STMT_EXPR,
|
|
|
|
STMT_FUN,
|
|
|
|
STMT_IF,
|
|
|
|
STMT_PRINT,
|
|
|
|
STMT_VAR,
|
|
|
|
STMT_WHILE,
|
|
|
|
STMT_COUNT,
|
|
|
|
} stmt_type_t;
|
|
|
|
|
|
|
|
typedef struct stmt_t {
|
|
|
|
stmt_type_t type;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
struct stmt_t **statements;
|
|
|
|
} block;
|
|
|
|
struct {
|
|
|
|
token_t name;
|
|
|
|
token_t superclass;
|
|
|
|
struct stmt_t **methods;
|
|
|
|
} class;
|
|
|
|
struct {
|
|
|
|
expr_t *expression;
|
|
|
|
} expr;
|
|
|
|
struct {
|
|
|
|
token_t name;
|
|
|
|
array_t *params;
|
|
|
|
struct stmt_t **body;
|
|
|
|
} function;
|
|
|
|
struct {
|
|
|
|
expr_t *condition;
|
|
|
|
struct stmt_t *thenBranch;
|
|
|
|
struct stmt_t *elseBranch;
|
|
|
|
} _if;
|
|
|
|
struct {
|
|
|
|
expr_t *expression;
|
|
|
|
} print;
|
|
|
|
struct {
|
|
|
|
token_t keyword;
|
|
|
|
expr_t *value;
|
|
|
|
} _return;
|
|
|
|
struct {
|
|
|
|
token_t name;
|
|
|
|
expr_t *initializer;
|
|
|
|
} variable;
|
|
|
|
struct {
|
|
|
|
expr_t *condition;
|
|
|
|
struct stmt_t *body;
|
|
|
|
} _while;
|
|
|
|
} as;
|
|
|
|
} stmt_t;
|
|
|
|
|
2025-01-06 03:00:01 +01:00
|
|
|
typedef struct {
|
2025-01-06 04:53:15 +01:00
|
|
|
struct stmt_t *statements;
|
|
|
|
int length;
|
|
|
|
int capacity;
|
|
|
|
} stmt_array_t;
|
|
|
|
|
2025-01-06 03:00:01 +01:00
|
|
|
#endif
|