160 |
else |
else |
161 |
def_sym(in_hash, in_string); /* Make symbol */ |
def_sym(in_hash, in_string); /* Make symbol */ |
162 |
|
|
163 |
new_item->content.ptr= *hash(in_hash, in_string); /* XXX */ |
new_item->content.ptr= *hash(in_hash, in_string); /* The new reference |
164 |
|
shouldn't point at |
165 |
|
NULL */ |
166 |
new_item->type= ref; |
new_item->type= ref; |
167 |
} |
} |
168 |
|
|
198 |
} |
} |
199 |
|
|
200 |
/* Prints the top element of the stack. */ |
/* Prints the top element of the stack. */ |
201 |
void print_(stackitem** stack_head) |
extern void print_(stackitem** stack_head) |
202 |
{ |
{ |
203 |
if((*stack_head)==NULL) { |
stackitem* temp= *stack_head; |
204 |
|
|
205 |
|
if(temp==NULL) { |
206 |
printerr("Stack empty"); |
printerr("Stack empty"); |
207 |
return; |
return; |
208 |
} |
} |
209 |
|
|
210 |
switch((*stack_head)->type) { |
while(temp->type==ref) |
211 |
|
temp= temp->content.ptr; |
212 |
|
|
213 |
|
switch(temp->type) { |
214 |
case value: |
case value: |
215 |
printf("%d", (*stack_head)->content.val); |
printf("%d", temp->content.val); |
216 |
break; |
break; |
217 |
case string: |
case string: |
218 |
printf("\"%s\"", (char*)(*stack_head)->content.ptr); |
printf("\"%s\"", (char*)temp->content.ptr); |
|
break; |
|
|
case ref: |
|
|
printf("%s", ((stackitem*)(*stack_head)->content.ptr)->id); |
|
219 |
break; |
break; |
220 |
case symbol: |
case symbol: |
221 |
|
printf("%s", temp->id); |
222 |
|
break; |
223 |
default: |
default: |
224 |
printf("%p", (*stack_head)->content.ptr); |
printf("%p", temp->content.ptr); |
225 |
break; |
break; |
226 |
} |
} |
227 |
} |
} |
286 |
void* delimiter; |
void* delimiter; |
287 |
stackitem *iterator, *temp, *pack; |
stackitem *iterator, *temp, *pack; |
288 |
|
|
|
if((*stack_head)==NULL) { |
|
|
printerr("Stack empty"); |
|
|
return; |
|
|
} |
|
|
|
|
289 |
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
290 |
toss(stack_head); |
toss(stack_head); |
291 |
|
|
292 |
iterator= *stack_head; |
iterator= *stack_head; |
293 |
|
|
294 |
/* Search for first delimiter */ |
if(iterator==NULL || iterator->content.ptr==delimiter) { |
295 |
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
temp= NULL; |
|
iterator= iterator->next; |
|
|
|
|
|
/* Extract list */ |
|
|
temp= *stack_head; |
|
|
*stack_head= iterator->next; |
|
|
iterator->next= NULL; |
|
|
|
|
|
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
|
296 |
toss(stack_head); |
toss(stack_head); |
297 |
|
} else { |
298 |
|
/* Search for first delimiter */ |
299 |
|
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
300 |
|
iterator= iterator->next; |
301 |
|
|
302 |
|
/* Extract list */ |
303 |
|
temp= *stack_head; |
304 |
|
*stack_head= iterator->next; |
305 |
|
iterator->next= NULL; |
306 |
|
|
307 |
|
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
308 |
|
toss(stack_head); |
309 |
|
} |
310 |
|
|
311 |
/* Push list */ |
/* Push list */ |
312 |
pack= malloc(sizeof(stackitem)); |
pack= malloc(sizeof(stackitem)); |
407 |
new_head= temp= (*stack_head)->content.ptr; |
new_head= temp= (*stack_head)->content.ptr; |
408 |
toss(stack_head); |
toss(stack_head); |
409 |
|
|
410 |
|
if(temp==NULL) |
411 |
|
return; |
412 |
|
|
413 |
/* Search the end of the list */ |
/* Search the end of the list */ |
414 |
while(temp->next!=NULL) |
while(temp->next!=NULL) |
415 |
temp= temp->next; |
temp= temp->next; |
506 |
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
507 |
} |
} |
508 |
|
|
509 |
|
/* Clear stack */ |
510 |
|
extern void clear(stackitem** stack_head) |
511 |
|
{ |
512 |
|
while(*stack_head!=NULL) |
513 |
|
toss(stack_head); |
514 |
|
} |
515 |
|
|
516 |
int main() |
int main() |
517 |
{ |
{ |
518 |
stackitem* s= NULL; |
stackitem* s= NULL; |