codebased/include/scirpt/ast.h
2023-04-14 02:17:45 +02:00

53 lines
1.0 KiB
C

#ifndef SCIRPT_AST_H
#define SCIRPT_AST_H
#include "common/generic_array.h"
#include "common/string.h"
#include "scirpt/position.h"
#include <stdbool.h>
#include <stdint.h>
typedef enum {
ScirptAstExprTypeEof,
ScirptAstExprTypeError,
ScirptAstExprTypeId,
ScirptAstExprTypeInt,
ScirptAstExprTypeString,
ScirptAstExprTypeNull,
ScirptAstExprTypeBool,
ScirptAstExprTypeBlock,
ScirptAstExprTypeIf,
} ScirptAstExprType;
typedef struct ScirptAstExpr ScirptAstExpr;
GENERIC_ARRAY(ScirptAstExpr*, ScirptAstExprArray, scirpt_ast_expr_array)
typedef struct {
ScirptAstExprArray statements;
ScirptAstExpr* value;
} ScirptAstExprBlock;
typedef struct {
ScirptAstExpr* condition;
ScirptAstExpr* truthy;
ScirptAstExpr* falsy;
} ScirptAstExprIf;
struct ScirptAstExpr {
ScirptAstExprType type;
ScirptPosition pos;
union {
HeapString id_value;
int64_t int_value;
HeapString string_value;
bool bool_value;
ScirptAstExprBlock block;
ScirptAstExprIf if_expr;
};
};
void scirpt_ast_expr_delete(ScirptAstExpr* expr);
#endif