Infinity Calculator implementation for Assignment 2 in Computer Organization.
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.
 
 

46 lines
768 B

#include <stdio.h>
#include <stdlib.h>
#include "expr.h"
#include "infint.h"
#include "parse.h"
#include "eval.h"
void eval_line(char *line) {
input_str = line;
expr_t *e = parse(0);
if (!e) return;
#ifdef UNIT_TESTS
print_expr_tree(e, 0);
#endif
infint_t *iie = evaluate(e);
char *iistr = infint_to_string(iie);
printf("%s\n", iistr);
free(iistr);
infint_free(iie);
destroy_expr(e);
}
int main() {
#ifdef UNIT_TESTS
test_infint();
test_expr_and_parse();
test_evaluate();
printf("**********************\n| All tests passed |\n**********************\n");
#endif
char *line = NULL;
size_t line_len = 0;
while(getline(&line,&line_len,stdin) != -1){
if (*line != '\n') {
eval_line(line);
}
free(line);
line = NULL;
}
free(line);
}