step: add an error message for wrong op-number order.
This commit is contained in:
parent
fc26fdf0f0
commit
85d2ede92d
22
src/mumble.c
22
src/mumble.c
|
@ -233,7 +233,7 @@ lispval* builtin_op(char* op, lispval* v){
|
||||||
// For now, ensure all args are numbers
|
// For now, ensure all args are numbers
|
||||||
for(int i=0; i<v->count; i++){
|
for(int i=0; i<v->count; i++){
|
||||||
if(v->cell[i]->type != LISPVAL_NUM){
|
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
|
// Check how many elements
|
||||||
|
@ -338,23 +338,27 @@ int main(int argc, char** argv)
|
||||||
mpc_ast_t* ast = result.output;
|
mpc_ast_t* ast = result.output;
|
||||||
|
|
||||||
// Print AST if VERBOSE
|
// Print AST if VERBOSE
|
||||||
if (VERBOSE)
|
if (VERBOSE){
|
||||||
|
printf("\nPrinting AST");
|
||||||
print_ast(ast, 0);
|
print_ast(ast, 0);
|
||||||
|
}
|
||||||
// Evaluate the AST
|
// Evaluate the AST
|
||||||
// if(VERBOSE) printf("\n\nEvaluating the AST");
|
// if(VERBOSE) printf("\n\nEvaluating the AST");
|
||||||
// lispval result = evaluate_ast(ast);
|
// lispval result = evaluate_ast(ast);
|
||||||
lispval* l = read_lispval(ast);
|
lispval* l = read_lispval(ast);
|
||||||
if (VERBOSE){
|
if (VERBOSE){
|
||||||
printf("\n\nTree printing: ");
|
printf("\n\nPrinting initially parsed lispvalue");
|
||||||
print_lispval_tree(l, 0);
|
printf("\nTree printing: ");
|
||||||
}
|
print_lispval_tree(l, 2);
|
||||||
if (VERBOSE){
|
printf("\nParenthesis printing: ");
|
||||||
printf("\nParenthesis printing: \n");
|
|
||||||
print_lispval_parenthesis(l);
|
print_lispval_parenthesis(l);
|
||||||
}
|
}
|
||||||
lispval* result = evaluate_lispval(l);
|
lispval* result = evaluate_lispval(l);
|
||||||
printf("\n"); print_lispval_parenthesis(result);
|
{
|
||||||
|
printf("\n\nResult: ");
|
||||||
|
print_lispval_parenthesis(result);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
delete_lispval(l);
|
delete_lispval(l);
|
||||||
} else {
|
} else {
|
||||||
/* Otherwise Print the Error */
|
/* Otherwise Print the Error */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user