Replace print/println keywords with generic function call mechanism

- Add NODE_CALL with name, args, and arg_count to parser
- Add TOK_COMMA token and tokenize (, ), , in lexer
- Remove TOK_PRINT/TOK_PRINTLN keywords; print/println are now regular
  identifiers resolved as built-in functions in the evaluator
- Add NODE_CALL debug output in ast_print
This commit is contained in:
Jose Luis Montañes Ojados
2026-02-16 18:14:39 +01:00
parent dd67537598
commit a36e52a9c3
4 changed files with 97 additions and 37 deletions

View File

@@ -83,7 +83,8 @@ size_t eval(ASTNode *node, Environment *env, void *allocator, int debug,
l->data.string_val.length);
// Copy right text
memcpy(tempBuff + l->data.string_val.length, JLANG_RESOLVE(allocator, r->data.string_val.chars),
memcpy(tempBuff + l->data.string_val.length,
JLANG_RESOLVE(allocator, r->data.string_val.chars),
r->data.string_val.length);
tempBuff[n] = '\0';
@@ -145,6 +146,31 @@ size_t eval(ASTNode *node, Environment *env, void *allocator, int debug,
}
break;
}
case NODE_CALL: {
if (strcmp(node->data.call.name, "print") == 0) {
if (node->data.call.arg_count > 0) {
size_t val = eval(node->data.call.args[0], env, allocator, debug, gc);
obj_print(allocator, val, "");
return val;
}
printf("");
return 0;
}
if (strcmp(node->data.call.name, "println") == 0) {
if (node->data.call.arg_count > 0) {
size_t val = eval(node->data.call.args[0], env, allocator, debug, gc);
obj_print(allocator, val, "");
printf("\n");
return val;
}
printf("\n");
return 0;
}
printf("ERROR: funcion '%s' no definida\n", node->data.call.name);
exit(1);
}
default:
break;
}