|
// 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"
|
|
|
|
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() {
|
|
rip_ast_t *ast = malloc(sizeof(rip_ast_t));
|
|
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();
|
|
while (1) {
|
|
rip_ast_t *statement = rip_parse();
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
int main() {
|
|
char *script = "{print(\"test\")}";
|
|
rlex(script);
|
|
while (1) {
|
|
rtoken_t token = rlex_next();
|
|
if (token.type == RT_CURLY_BRACE_OPEN) {
|
|
// handle open
|
|
}
|
|
}
|
|
return 0;
|
|
} |