-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.c
41 lines (32 loc) · 757 Bytes
/
shell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "lispy.h"
#include <stdio.h>
#include <stdlib.h>
#include <editline/readline.h>
#include <histedit.h>
/* Parsing Stuff */
int main(int argc, char** argv){
puts("Lispy Version 0.0.1");
puts("Press Ctrl+c to Exit\n");
while(1) {
/* Prompt and readline */
char* input = readline("lispy> ");
if(!input) {
printf("\n");
continue;
}
if(input[0]){
add_history(input);
}
/* Try to parse stuff and print out the AST. Otherwise print the error */
mpc_result_t r;
if(lispy_parse("<stdin>", input, &r)){
lval_println(eval(r.output));
mpc_ast_delete(r.output);
} else {
mpc_err_print(r.error);
mpc_err_delete(r.error);
}
free(input);
}
return 0;
}