Files
lisp/main.c
T

50 lines
1.0 KiB
C

#include <stdio.h>
#define NOB_IMPLEMENTATION
#include "lisp.h"
int main(int argc, char **argv) {
if (argc < 2)
return 1;
argv++;
const char *line = *argv++;
Nob_String_View view = nob_sv_from_cstr(line);
if (nob_sv_eq(view, (Nob_String_View){.count = 1, .data = "-"})) {
printf("Reading from stdin\n");
Nob_String_Builder sb = {0};
char content[1];
while (read(stdin->_fileno, content, sizeof(*content)) == 1) {
if (*content == '\0')
break;
nob_sb_appendf(&sb, "%c", *content);
}
view = nob_sb_to_sv(sb);
}
Tokens tokens = {0};
tokenize(view, &tokens);
#if 0
for (size_t i = 0; i < tokens.count; i++) {
Token tok = tokens.items[i];
printf("Token(kind=%s, data=" SV_Fmt ")\n", token_kind_name(tok.kind),
SV_Arg(tok.data));
}
#endif
Node *result = parse(&tokens);
if (result == NULL)
return 1;
result = eval(result);
node_print(*result);
printf("\n");
return 0;
}