- Implement string literal tokenization and parsing (lexer + parser) - Add string concatenation with + operator in evaluator - Add println keyword for printing with newline - Add NODE_IF evaluation in VM - Fix null terminator bug in string concat buffer
43 lines
1.0 KiB
C
43 lines
1.0 KiB
C
#include "vm/eval.h"
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc != 2) {
|
|
printf("usage: %s <path to .j file>\n", argv[0]);
|
|
exit(1);
|
|
}
|
|
// Creamos un allocator
|
|
JLANG_memory_allocator *allocPtr = JLANG_CreateAllocator();
|
|
|
|
// Read file from argv
|
|
FILE *fptr = fopen(argv[1], "r");
|
|
if (fptr == NULL) {
|
|
printf("error leyendo: %s\n", argv[1]);
|
|
exit(1);
|
|
}
|
|
|
|
fseek(fptr, 0, SEEK_END); // ir al final
|
|
long length = ftell(fptr); // cuántos bytes tiene
|
|
fseek(fptr, 0, SEEK_SET); // volver al inicio
|
|
char *buff = malloc(length + 1);
|
|
size_t bytesRead = fread(buff, 1, length, fptr);
|
|
buff[bytesRead] = '\0';
|
|
|
|
fclose(fptr);
|
|
|
|
printf("%s\n", buff);
|
|
|
|
// Lexer test
|
|
int totalTokens = 0;
|
|
Token *tokens = tokenize(buff, &totalTokens);
|
|
printf("totalTokens=%d\n", totalTokens);
|
|
ASTNode *block = parse(tokens, totalTokens);
|
|
ast_debug(block);
|
|
|
|
Environment env = {0};
|
|
eval(block, &env, allocPtr, 0, 1);
|
|
|
|
printf("heapSize=%zu\n", allocPtr->size);
|
|
JLANG_visualize(allocPtr);
|
|
|
|
return 0;
|
|
} |