51 lines
1.2 KiB
C
Raw Normal View History

2025-03-16 05:49:29 +01:00
// Written by retoor@molodetz.nl
// This code defines an abstract syntax tree (AST) for a scripting language, implements AST node creation, and attempts to parse tokens from
// a lexer.
// No additional imports or includes are used outside of the provided rlexer.c file.
// MIT License
#include "rlexer.c"
2025-01-14 18:53:15 +01:00
typedef enum rip_ast_type_t { RIP_NONE = 0, RIP_BLOCK, RIP_CALL, RIP_LITERAL } rip_ast_type_t;
typedef struct rip_ast_t {
struct rip_ast_t *children;
struct rip_ast_t *next;
struct rip_ast_t *previous;
rip_ast_type_t type;
} rip_ast_t;
rip_ast_t *rip_ast_new() {
2025-03-16 05:49:29 +01:00
rip_ast_t *ast = malloc(sizeof(rip_ast_t));
2025-01-14 18:53:15 +01:00
ast->children = NULL;
ast->next = NULL;
ast->previous = NULL;
ast->type = RIP_NONE;
return ast;
}
rip_ast_t *rip_parse() {
rtoken_t token = rlex_next();
if (token.type == RT_CURLY_BRACE_OPEN) {
rip_ast_t *ast = rip_ast_new();
2025-03-16 05:49:29 +01:00
while (1) {
2025-01-14 18:53:15 +01:00
rip_ast_t *statement = rip_parse();
2025-03-16 05:49:29 +01:00
}
2025-01-14 18:53:15 +01:00
}
2025-03-16 05:49:29 +01:00
return NULL;
2025-01-14 18:53:15 +01:00
}
int main() {
char *script = "{print(\"test\")}";
rlex(script);
2025-03-16 05:49:29 +01:00
while (1) {
2025-01-14 18:53:15 +01:00
rtoken_t token = rlex_next();
2025-03-16 05:49:29 +01:00
if (token.type == RT_CURLY_BRACE_OPEN) {
// handle open
2025-01-14 18:53:15 +01:00
}
}
2025-03-16 05:49:29 +01:00
return 0;
2025-01-14 18:53:15 +01:00
}