diff options
| author | Mistivia <i@mistivia.com> | 2025-06-19 17:30:06 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-06-19 17:30:06 +0800 |
| commit | dc2136d7306d99e9b374f4ce758571edfcca6075 (patch) | |
| tree | 5b59741c08e81b828ee9f4aee60931dac287ac84 /src/main.c | |
| parent | 5cf6d5b34c2bdb42af5b3551378026079435a3b8 (diff) | |
basic function: car/cdr/cons/+/-
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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; } |
