mumble

A Lisp written in C, following the *Build Your Own Lisp* book
Log | Files | Refs | README

commit 85d2ede92d8754af484d7423e9a1541060999e82
parent fc26fdf0f0f0530dde74c2a5c4cf6db174ecfec9
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Mon,  1 May 2023 20:04:48 -0400

step: add an error message for wrong op-number order.

Diffstat:
Mmumble | 0
Msrc/mumble.c | 22+++++++++++++---------
2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/mumble b/mumble Binary files differ. diff --git a/src/mumble.c b/src/mumble.c @@ -233,7 +233,7 @@ lispval* builtin_op(char* op, lispval* v){ // For now, ensure all args are numbers for(int i=0; i<v->count; i++){ if(v->cell[i]->type != LISPVAL_NUM){ - return lispval_err("Error: Operating on non-numbers"); + return lispval_err("Error: Operating on non-numbers. This can be caused by an input like (+ 1 2 (3 * 4)). Because the (3 * 4) doesn't have the correct operation order, it isn't simplified, and then + can't sum over it."); } } // Check how many elements @@ -338,23 +338,27 @@ int main(int argc, char** argv) mpc_ast_t* ast = result.output; // Print AST if VERBOSE - if (VERBOSE) + if (VERBOSE){ + printf("\nPrinting AST"); print_ast(ast, 0); - + } // Evaluate the AST // if(VERBOSE) printf("\n\nEvaluating the AST"); // lispval result = evaluate_ast(ast); lispval* l = read_lispval(ast); if (VERBOSE){ - printf("\n\nTree printing: "); - print_lispval_tree(l, 0); - } - if (VERBOSE){ - printf("\nParenthesis printing: \n"); + printf("\n\nPrinting initially parsed lispvalue"); + printf("\nTree printing: "); + print_lispval_tree(l, 2); + printf("\nParenthesis printing: "); print_lispval_parenthesis(l); } lispval* result = evaluate_lispval(l); - printf("\n"); print_lispval_parenthesis(result); + { + printf("\n\nResult: "); + print_lispval_parenthesis(result); + printf("\n"); + } delete_lispval(l); } else { /* Otherwise Print the Error */