-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
56 lines (44 loc) · 928 Bytes
/
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
50
51
52
53
54
55
56
/* IFJ Project 2018/19
* Implementation of Stack of tokens
*
* TEAM:
* Simon Kobyda
* Michal Zelenak
* Juraj Samuel Salon
* Denis Filo
*
* FILE: stack.c
* FILE AUTHOR: Simon Kobyda
*/
/***SYSTEM FILES***/
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
/***LOCAL FILES***/
#include "scanner.h"
#include "stack.h"
StackPtr StackCreate() {
StackPtr stack = malloc(sizeof(struct Stack));
if (!stack)
return NULL;
stack->top = 0;
return stack;
}
void StackDestroy(StackPtr stack) {
if (!stack)
return;
for (int i = 0; i < stack->top; i++) {
free(stack->arr[i]->name);
free(stack->arr[i]);
}
free(stack);
}
bool StackPush(StackPtr stack, TokenPtr token) {
stack->arr[stack->top++] = token;
return true;
}
TokenPtr StackPop(StackPtr stack) {
if(!stack->top)
return NULL;
return stack->arr[--stack->top];
}