-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
78 lines (65 loc) · 1.58 KB
/
stack.c
File metadata and controls
78 lines (65 loc) · 1.58 KB
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
#include <stdlib.h> // for malloc
#include <string.h>
#include "stack.h" // STACK header
Instr* stack_Instr1(Ikind kind,int arg){
Instr* node = (Instr*) malloc(sizeof(Instr*));
node->kind = kind;
node->attr.arg = arg;
node->arg_kind = val;
return node;
}
Instr* stack_Instr2(Ikind kind,char* id){
Instr* node = (Instr*) malloc(sizeof(Instr*));
node->kind = kind;
node->attr.id = id;
node->arg_kind = var;
return node;
}
Instr* stack_Instr3(Ikind kind){
Instr* node = (Instr*) malloc(sizeof(Instr*));
node->kind = kind;
node->arg_kind = none;
return node;
}
Instr* head(InstrList* l){ return l->code;};
InstrList* tail(InstrList* l){ return l->next;};
InstrList* append(InstrList* l1, InstrList* l2){
if(l1==NULL)
return l2;
else{
return stack_InstrList(head(l1),append(tail(l1),l2));
}
}
InstrList* stack_InstrList(Instr* code,InstrList* next){
InstrList* node = (InstrList*) malloc(sizeof(InstrList*));
node->code = code;
node->next = next;
return node;
}
varList* stack_varList(char* var, varList* next){
varList* node = (varList*) malloc(sizeof(varList*));
node->var = var;
node->next = next;
return node;
}
int varListContains(char* var,varList* varlist){
varList* l = varlist;
while(l != NULL){
if(strcmp(l->var,var) == 0){
return 1;
}
else{
l = l->next;
}
}
return 0;
}
char* head2(varList* v){ return v->var;};
varList* tail2(varList* v){return v->next;};
varList* append2(varList* l1, varList* l2){
if(l1==NULL)
return l2;
else{
return stack_varList(head2(l1),append2(tail2(l1),l2));
}
}