aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-19 17:30:06 +0800
committerMistivia <i@mistivia.com>2025-06-19 17:30:06 +0800
commitdc2136d7306d99e9b374f4ce758571edfcca6075 (patch)
tree5b59741c08e81b828ee9f4aee60931dac287ac84 /src/main.c
parent5cf6d5b34c2bdb42af5b3551378026079435a3b8 (diff)
basic function: car/cdr/cons/+/-
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 33c14ce..ecbc2f4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,3 +1,36 @@
+#include "interp.h"
+#include "parser.h"
+#include "sexp.h"
+
int main() {
+ int ret = -1;
+ Interp interp;
+ Parser parser;
+ Interp_init(&interp);
+ Parser_init(&parser);
+ parser.ctx = &interp;
+
+ Parser_set_file(&parser, stdin);
+ SExpRef sexp, res;
+ ParseResult parse_result;
+ while (1) {
+ printf("> ");
+ parse_result = parse_sexp(&parser);
+ if (parse_result.errmsg != NULL) {
+ if (Parser_peek(&parser) == EOF) goto end;
+ fprintf(stderr, "Parsing error: %s", parse_result.errmsg);
+ continue;
+ }
+
+ res = lisp_eval(&interp, parse_result.val);
+ if (Interp_ref(&interp, res)->type == kErrSExp) {
+ fprintf(stderr, "Eval error: %s", Interp_ref(&interp, res)->str);
+ continue;
+ }
+ lisp_print(&interp, res, stdout);
+ }
+end:
+ Parser_free(&parser);
+ Interp_free(&interp);
return 0;
}