-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
42 lines (35 loc) · 821 Bytes
/
parser.h
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
#ifndef PARSER_H
#define PARSER_H
typedef struct instruction {
Instruction* next;
char* line;
} Instruction;
typedef struct program {
int lines;
// When a program is loaded in, we add it to a singly linked list for later parsing and for debugging
Instruction* start;
Instruction* end;
} Program;
// Program constructor.
void init_program(Program* loc) {
loc->lines = 0;
loc->start = NULL;
loc->end = NULL;
}
// And destructor
void cleanup_program(Program* loc) {
Instruction* itr = loc->start;
while (itr != NULL) {
free(itr->line);
Instruction* prev_itr = itr;
itr = itr->next;
free(prev_itr);
}
loc->start = NULL;
loc->end = NULL;
}
void append_instruction(Program* prog, char* inst) {
prog->end->next = (Instruction*) malloc(sizeof(Instruction));
prog->end = prog->end->next;
}
#endif