Add lexer, parser and AST debug printer
Implements tokenizer for basic tokens (INT, ID, ASSIGN, PLUS, MINUS, NEWLINE, PRINT), recursive descent parser for assignments and binary expressions, and tree-formatted AST visualization with ast_debug().
This commit is contained in:
14
src/main.c
14
src/main.c
@@ -1,3 +1,4 @@
|
||||
#include "frontend/parser.h"
|
||||
#include "objects/object.h"
|
||||
|
||||
int main() {
|
||||
@@ -13,20 +14,25 @@ int main() {
|
||||
items[0] = floatVar1;
|
||||
items[1] = stringVar1;
|
||||
items[2] = listVar1;
|
||||
|
||||
|
||||
obj_print(allocPtr, listVar1, "");
|
||||
|
||||
obj_free(allocPtr, stringVar1);
|
||||
|
||||
stringVar1 = obj_new_string(allocPtr, "Hola Mundo!");
|
||||
stringVar1 = obj_new_string(allocPtr, "Hola Mundo!");
|
||||
items[1] = stringVar1;
|
||||
items[2] = stringVar1;
|
||||
|
||||
|
||||
|
||||
obj_print(allocPtr, listVar1, "");
|
||||
|
||||
JLANG_visualize(allocPtr);
|
||||
|
||||
// Lexer test
|
||||
int totalTokens = 0;
|
||||
Token *tokens = tokenize("x = 10\ny = 5\nz = x + y\nprint z", &totalTokens);
|
||||
printf("totalTokens=%d\n", totalTokens);
|
||||
ASTNode* block = parse(tokens, totalTokens);
|
||||
ast_debug(block);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user