step: make top level interpretation more parsimonious

This commit is contained in:
NunoSempere 2023-05-01 21:36:50 -04:00
parent e064fd5ec9
commit cf61eb6e98
2 changed files with 16 additions and 1 deletions

BIN
mumble

Binary file not shown.

View File

@ -116,12 +116,27 @@ lispval* read_lispval_num(mpc_ast_t* t)
} }
lispval* read_lispval(mpc_ast_t* t) lispval* read_lispval(mpc_ast_t* t)
{ {
// Non-ignorable children
// Relevant for the edge-case of considering the case where you
// only have one top level item.
int c = 0;
int c_index = -1;
for(int i=0; i<t->children_num; i++){
mpc_ast_t* child = t->children[i];
if( ( strcmp(child->tag, "regex") != 0 ) || (strcmp(child->contents, "") != 0 ) || child->children_num != 0 ){
c++;
c_index = i;
}
}
if(VERBOSE) printf("\nNon ignorable children: %i", c);
if (strstr(t->tag, "number")) { if (strstr(t->tag, "number")) {
return read_lispval_num(t); return read_lispval_num(t);
} else if (strstr(t->tag, "symbol")) { } else if (strstr(t->tag, "symbol")) {
return lispval_sym(t->contents); return lispval_sym(t->contents);
} else if ((strcmp(t->tag, ">") == 0) && (c==1)) {
return read_lispval(t->children[c_index]);
} else if ((strcmp(t->tag, ">") == 0) || strstr(t->tag, "sexpr") || strstr(t->tag, "qexpr")) { } else if ((strcmp(t->tag, ">") == 0) || strstr(t->tag, "sexpr") || strstr(t->tag, "qexpr")) {
lispval* x; lispval* x;
if((strcmp(t->tag, ">") == 0) || strstr(t->tag, "sexpr")){ if((strcmp(t->tag, ">") == 0) || strstr(t->tag, "sexpr")){
x = lispval_sexpr(); x = lispval_sexpr();