Camden Dixie O'Brien 4c24611172 Remove \n from puts() call
The newline is added by puts() so this led to double newlines.
2024-10-24 22:54:11 +01:00

39 lines
633 B
C

#include <stdio.h>
#include <stdlib.h>
#include "evaluator.h"
#include "reader.h"
#define BUFFER_SIZE 128U
static memory_pool_t pool;
static char buffer[BUFFER_SIZE];
static bool step_repl(void)
{
init_memory_pool(&pool);
const int len = read_line(getchar, buffer, BUFFER_SIZE);
if (len < 0)
return false;
expression_t *expression;
const int used = parse_expression(&pool, buffer, len, &expression);
if (used != len) {
puts("Invalid expression");
return true;
}
const int result = evaluate(expression);
printf("%d\n", result);
return true;
}
int main(void)
{
while (step_repl())
;
return EXIT_SUCCESS;
}