compiler/include/ast.h

38 lines
797 B
C
Raw Permalink Normal View History

2024-07-21 02:04:32 +12:00
#include <slibs/slibs.h>
#include <tokenizer.h>
#ifndef __AST_H__
#define __AST_H__
extern const char *ASTTypeText[];
2024-07-21 02:04:32 +12:00
typedef enum ASTType {
AST_PROGRAM,
AST_CALL_EXPRESSION,
AST_NUMBER_LITERAL,
AST_STRING_LITERAL,
AST_NONE
2024-07-21 02:04:32 +12:00
} ASTType;
typedef sl_vec(struct ASTNode) ASTVec;
2024-07-21 02:04:32 +12:00
typedef struct ASTNode {
ASTType type;
const char *name;
const char *value;
2024-07-21 02:04:32 +12:00
ASTVec body;
ASTVec params;
2024-07-21 02:04:32 +12:00
} ASTNode;
ASTNode ast_parse(TokenVec *tokens);
ASTNode ast_walk(TokenVec *tokens);
void ast_print(ASTNode node, int indent);
ASTNode ast_create_empty(ASTType type);
ASTNode ast_create_program(ASTVec body);
ASTNode ast_create_call_expression(const char *name, ASTVec params);
ASTNode ast_create_number_literal(const char *value);
ASTNode ast_create_string_literal(const char *value);
2024-07-21 02:04:32 +12:00
#endif