| 208 |
printf("%d", (*stack_head)->content.val); |
printf("%d", (*stack_head)->content.val); |
| 209 |
break; |
break; |
| 210 |
case string: |
case string: |
| 211 |
printf("%s", (char*)(*stack_head)->content.ptr); |
printf("\"%s\"", (char*)(*stack_head)->content.ptr); |
| 212 |
break; |
break; |
| 213 |
case ref: |
case ref: |
| 214 |
printf("%s", ((stackitem*)(*stack_head)->content.ptr)->id); |
printf("%s", ((stackitem*)(*stack_head)->content.ptr)->id); |
| 243 |
{ |
{ |
| 244 |
if(*stack_head != NULL) { |
if(*stack_head != NULL) { |
| 245 |
print_st(*stack_head, 1); |
print_st(*stack_head, 1); |
| 246 |
printf("\n"); |
nl(); |
| 247 |
} else { |
} else { |
| 248 |
printerr("Stack empty"); |
printerr("Stack empty"); |
| 249 |
} |
} |
| 254 |
extern void eval(stackitem** stack_head) |
extern void eval(stackitem** stack_head) |
| 255 |
{ |
{ |
| 256 |
funcp in_func; |
funcp in_func; |
| 257 |
|
stackitem* temp= *stack_head; |
| 258 |
|
|
| 259 |
if((*stack_head)==NULL || (*stack_head)->type!=ref) { |
if(temp==NULL) { |
| 260 |
printerr("Stack empty or not a reference"); |
printerr("Stack empty"); |
| 261 |
return; |
return; |
| 262 |
} |
} |
| 263 |
|
|
| 264 |
if(((stackitem*)(*stack_head)->content.ptr)->type==func) { |
while(temp->type==ref) |
| 265 |
in_func= (funcp)((stackitem*)(*stack_head)->content.ptr)->content.ptr; |
temp= temp->content.ptr; |
| 266 |
|
|
| 267 |
|
if(temp->type==func) { |
| 268 |
|
in_func= (funcp)(temp->content.ptr); |
| 269 |
toss(stack_head); |
toss(stack_head); |
| 270 |
(*in_func)(stack_head); |
(*in_func)(stack_head); |
| 271 |
return; |
return; |
| 272 |
} else |
} |
| 273 |
printerr("Not a function"); |
|
| 274 |
|
printerr("Couldn't evaluate"); |
| 275 |
|
} |
| 276 |
|
|
| 277 |
|
/* Make a list. */ |
| 278 |
|
extern void pack(stackitem** stack_head) |
| 279 |
|
{ |
| 280 |
|
void* delimiter; |
| 281 |
|
stackitem *iterator, *temp, *pack; |
| 282 |
|
|
| 283 |
|
if((*stack_head)==NULL) { |
| 284 |
|
printerr("Stack empty"); |
| 285 |
|
return; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
| 289 |
|
toss(stack_head); |
| 290 |
|
|
| 291 |
|
iterator= *stack_head; |
| 292 |
|
|
| 293 |
|
/* Search for first delimiter */ |
| 294 |
|
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
| 295 |
|
iterator= iterator->next; |
| 296 |
|
|
| 297 |
|
/* Extract list */ |
| 298 |
|
temp= *stack_head; |
| 299 |
|
*stack_head= iterator->next; |
| 300 |
|
iterator->next= NULL; |
| 301 |
|
|
| 302 |
|
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
| 303 |
|
toss(stack_head); |
| 304 |
|
|
| 305 |
|
/* Push list */ |
| 306 |
|
pack= malloc(sizeof(stackitem)); |
| 307 |
|
pack->type= list; |
| 308 |
|
pack->content.ptr= temp; |
| 309 |
|
|
| 310 |
|
push(stack_head, pack); |
| 311 |
} |
} |
| 312 |
|
|
| 313 |
/* Parse input. */ |
/* Parse input. */ |
| 317 |
int itemp; |
int itemp; |
| 318 |
size_t inlength= strlen(in_line)+1; |
size_t inlength= strlen(in_line)+1; |
| 319 |
int convert= 0; |
int convert= 0; |
| 320 |
|
static int non_eval_flag= 0; |
| 321 |
|
|
| 322 |
temp= malloc(inlength); |
temp= malloc(inlength); |
| 323 |
rest= malloc(inlength); |
rest= malloc(inlength); |
| 340 |
break; |
break; |
| 341 |
} |
} |
| 342 |
/* If symbol */ |
/* If symbol */ |
| 343 |
if((convert= sscanf(in_line, "%[^ ;\n\r]%[^\n\r]", temp, rest))) { |
if((convert= sscanf(in_line, "%[^][ ;\n\r]%[^\n\r]", temp, rest))) { |
| 344 |
push_ref(stack_head, in_hash, temp); |
push_ref(stack_head, in_hash, temp); |
| 345 |
break; |
break; |
| 346 |
} |
} |
| 347 |
/* If ';' */ |
/* If single char */ |
| 348 |
if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest)) && *temp==';') { |
if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest))) { |
| 349 |
eval(stack_head); /* Evaluate top element */ |
if(*temp==';') { |
| 350 |
break; |
if(!non_eval_flag) { |
| 351 |
|
eval(stack_head); /* Evaluate top element */ |
| 352 |
|
break; |
| 353 |
|
} |
| 354 |
|
|
| 355 |
|
push_ref(stack_head, in_hash, ";"); |
| 356 |
|
break; |
| 357 |
|
} |
| 358 |
|
|
| 359 |
|
if(*temp==']') { |
| 360 |
|
push_ref(stack_head, in_hash, "["); |
| 361 |
|
pack(stack_head); |
| 362 |
|
if(non_eval_flag!=0) |
| 363 |
|
non_eval_flag--; |
| 364 |
|
break; |
| 365 |
|
} |
| 366 |
|
|
| 367 |
|
if(*temp=='[') { |
| 368 |
|
push_ref(stack_head, in_hash, "["); |
| 369 |
|
non_eval_flag++; |
| 370 |
|
break; |
| 371 |
|
} |
| 372 |
} |
} |
| 373 |
} while(0); |
} while(0); |
| 374 |
|
|
| 386 |
return 1; |
return 1; |
| 387 |
} |
} |
| 388 |
|
|
|
/* Make a list. */ |
|
|
extern void pack(stackitem** stack_head) |
|
|
{ |
|
|
void* delimiter; |
|
|
stackitem *iterator, *temp, *pack; |
|
|
|
|
|
if((*stack_head)==NULL) { |
|
|
printerr("Stack empty"); |
|
|
return; |
|
|
} |
|
|
|
|
|
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
|
|
toss(stack_head); |
|
|
|
|
|
iterator= *stack_head; |
|
|
|
|
|
/* Search for first delimiter */ |
|
|
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
|
|
iterator= iterator->next; |
|
|
|
|
|
/* Extract list */ |
|
|
temp= *stack_head; |
|
|
*stack_head= iterator->next; |
|
|
iterator->next= NULL; |
|
|
|
|
|
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
|
|
toss(stack_head); |
|
|
|
|
|
/* Push list */ |
|
|
pack= malloc(sizeof(stackitem)); |
|
|
pack->type= list; |
|
|
pack->content.ptr= temp; |
|
|
|
|
|
push(stack_head, pack); |
|
|
} |
|
|
|
|
| 389 |
/* Relocate elements of the list on the stack. */ |
/* Relocate elements of the list on the stack. */ |
| 390 |
extern void expand(stackitem** stack_head) |
extern void expand(stackitem** stack_head) |
| 391 |
{ |
{ |