-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.h
107 lines (93 loc) · 2.13 KB
/
stack.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
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
/**
* Implementace překladače imperativního jazyka IFJ22
*
* @file stack.h
* @author Josef Kuchař ([email protected])
* @author Matej Sirovatka ([email protected])
* @author Tomáš Běhal ([email protected])
* @author Šimon Benčík ([email protected])
* @brief Declarations of helper functions for working with stack
*/
#ifndef __STACK_H__
#define __STACK_H__
#include "token_term.h"
typedef struct {
token_term_t** tokens;
int len;
int size;
} stack_t;
/**
* @brief Initialize new stack struct
*
* @return New stack_t
*/
stack_t stack_new();
/**
* @brief Frees stack
*
* @param stack to be freed
*/
void stack_free(stack_t* stack);
/**
* @brief Removes all elements from stack (does not free stack)
*
* @param stack Stack
*/
void stack_empty(stack_t* stack);
/**
* @brief Pushes value on the stack
*
* @param stack to be pushed to, token to be pushed
*/
void stack_push(stack_t* stack, token_term_t* token);
/**
* @brief Removes and returns the top of the stack
*
* @param stack to be popped from
*
* @return token_term_t from top of the stack
*/
token_term_t* stack_pop(stack_t* stack);
/**
* @brief Returns top of the stack
*
* @param stack to be popped from
*
* @return token_term_t from top of the stack
*/
token_term_t* stack_top(stack_t* stack);
/**
* @brief Pretty prints stack
*
* @param stack to be printed
*/
void stack_pprint(stack_t* stack);
/**
* @brief Returns terminal closest to the top of the stack and removes it
*
* @param stack to be popped from
*
* @return token_term_t from top of the stack
*/
token_term_t* stack_pop_terminal(stack_t* stack);
/**
* @brief Returns terminal closest to the top of the stack
*
* @param stack to be popped from
*
* @return token_term_t from top of the stack
*/
token_term_t* stack_top_terminal(stack_t* stack);
/**
* @brief Pushes start_handle after the terminal closest to the top
*
* @param stack to be pushed to
*/
void stack_push_after_terminal(stack_t* stack);
/**
* @brief Resizes stack to twice the size
*
* @param stack to be resized
*/
void resize_stack(stack_t* stack);
#endif // __STACK_H__