-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatom.c
127 lines (79 loc) · 1.69 KB
/
atom.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
#include <stdlib.h>
#include "error.h"
#include "atom.h"
#include "stack.h"
struct atom *new_atom(){
struct atom *new;
new = calloc(1,sizeof(struct atom));
if(new == NULL)
error("Allocating Atom: Out of memory.");
return new;
}
void print_atom_type(struct atom *a){
printf("\tType:\t");
switch(a->type){
case START: printf("START\n");
break;
case TERM: printf("TERM\n");
break;
case JUMP: printf("JUMP\n");
break;
case INT: printf("INT\n");
break;
case FLOAT: printf("FLOAT\n");
break;
case STRING: printf("STRING\n");
break;
case CALL: printf("CALL\n");
break;
case REF: printf("REF\n");
break;
case EXIT: printf("EXIT\n");
break;
case IDENT: printf("IDENT\n");
break;
default:
error("Printing Atom Type: Unknown atom type");
}
}
void print_atom(struct atom *a){
switch(a->type){
case START:
break;
case TERM:
break;
case JUMP:
printf("%ld\n", (long) a->data.jump_t - (long) stack);
break;
case INT:
printf("%d\n", a->data.int_t);
break;
case FLOAT:
printf("%f\n", a->data.float_t);
break;
case STRING:
printf("%s\n", a->data.string_t);
break;
case CALL:
printf("%ld\n", (long) a->data.call_t - (long) stack);
break;
case REF:
printf("%ld\n", (long) a->data.jump_t - (long) stack);
break;
case EXIT:
break;
case IDENT:
printf("%s\n", a->data.string_t);
break;
default:
error("Pretty Printing Atom: Unknown atom type");
}
}
struct atom * cp_atom( struct atom *a){
struct atom *new;
new = new_atom();
new->type = a->type;
new->data = a->data;
return new;
}