-
Notifications
You must be signed in to change notification settings - Fork 1
/
t_stack.c
49 lines (38 loc) · 1002 Bytes
/
t_stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
#include "malloc.h"
#include "types.h"
#include "utils.h"
int main(int argc, char *argv[]) {
/* *
* This is used to test stack construction, it's expected to print
* '(+ 5 (* 2 1) 10)'
*/
struct stack_frame *top = NULL;
struct pair *p;
struct symbol *s;
struct number *n;
int dot_list = 0;
push_stack_frame(&top);
s = alloc_symbol("+");
append_stack(top, (struct exp *)s, &dot_list);
n = alloc_long(5);
append_stack(top, (struct exp *)n, &dot_list);
push_stack_frame(&top);
s = alloc_symbol("*");
append_stack(top, (struct exp *)s, &dot_list);
n = alloc_long(2);
append_stack(top, (struct exp *)n, &dot_list);
n = alloc_long(1);
append_stack(top, (struct exp *)n, &dot_list);
p = top->head;
pop_stack_frame(&top);
append_stack(top, (struct exp *)p, &dot_list);
n = alloc_long(10);
append_stack(top, (struct exp *)n, &dot_list);
p = top->head;
print(stdout, (struct exp *)p);
printf("\n");
exit(0);
}