(Somewhat adapted) code and solutions from the book "Build Your Own Lisp" http://www.buildyourownlisp.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

55 lines
1.1 KiB

#include <stdio.h>
#include <stdlib.h>
/* If we are on Windows compile these functions */
#ifdef _WIN32
#include <string.h>
#include <assert.h>
static char buffer[2048];
/* Fake readline function */
char* readline(char* prompt) {
fputs(prompt, stdout);
fgets(buffer, 2048, stdin);
char* cpy = malloc(strlen(buffer)+1);
assert(cpy != NULL)
strcpy(cpy, buffer);
cpy[strlen(cpy)-1] = '\0';
return cpy;
}
/* Fake add_history function */
void add_history(char* unused) {}
/* Otherwise include the editline headers
could use __APPLE__ for detection of OSX */
#else
#include <editline/readline.h>
#endif
int main(int argc, char const *argv[])
{
/* Print version and exit information */
puts("Lispy version 0.0.0.0.1");
puts("Press Ctrl+c to exit\n");
/* In a never ending loop */
while (1) {
/* Output our prompt and get input */
char* input = readline("lispy> ");
/* Add input to history */
add_history(input);
/* Echo input back to user */
printf("No you're a %s\n", input);
/* Free retrieved input */
free(input);
}
return 0;
}