Add missing clean targets in 5 impls.
[jackhill/mal.git] / c / step0_repl.c
CommitLineData
31690700
JM
1#include <stdlib.h>
2#include <stdio.h>
3#include <unistd.h>
4
5#ifdef USE_READLINE
6 #include <readline/readline.h>
7 #include <readline/history.h>
8#else
9 #include <editline/readline.h>
10#endif
11
12char *READ(char prompt[]) {
13 char *line;
14 line = readline(prompt);
15 if (!line) return NULL; // EOF
16 add_history(line); // Add input to history.
17 return line;
18}
19
20char *EVAL(char *ast, void *env) {
21 return ast;
22}
23
24char *PRINT(char *exp) {
25 return exp;
26}
27
28int main()
29{
30 char *ast, *exp;
31 char prompt[100];
32
33 // Set the initial prompt
34 snprintf(prompt, sizeof(prompt), "user> ");
dd7a4f55 35
31690700
JM
36 for(;;) {
37 ast = READ(prompt);
38 if (!ast) return 0;
39 exp = EVAL(ast, NULL);
6b3ecaa7 40 puts(PRINT(exp));
dd7a4f55 41
31690700
JM
42 free(ast); // Free input string
43 }
44}