-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
130 lines (110 loc) · 2.67 KB
/
stack.h
File metadata and controls
130 lines (110 loc) · 2.67 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
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
126
127
128
129
130
/**
* @project IFJ17
* @file stack.h
* @author Jan Bartosek (xbarto92)
* @author Roman Bartl (xbartl06)
* @brief Operations with Dynamic Stack
*/
#include "ast.h"
#include "scanner.h"
#ifndef IFJ2017_STACK_H
#define IFJ2017_STACK_H
#define MAX_VALUE 18
typedef enum {
PREC_MULTIPLY = 0,
PREC_DIVISION,
PREC_BACKSLASH,
PREC_PLUS,
PREC_MINUS,
PREC_ASSIGNMENT,
PREC_NOT_EQUAL,
PREC_LESS,
PREC_LESS_EQUAL,
PREC_GREATER,
PREC_GREATER_EQUAL,
PREC_BRACKET_LEFT,
PREC_BRACKET_RIGHT,
PREC_ID,
PREC_NUMBER,
PREC_DECIMAL_NUMBER,
PREC_STRING_EXPRESSION,
PREC_DOLLAR, // special symbol '$' in precedence table
PREC_E, // special symbol 'E' in precedence table
PREC_LT // special symbol '<' in precedence table
} precedStack;
typedef struct stackItem {
BinaryTreePtr *ptr;
ast_exp *Exp;
token Token;
precedStack symbol;
ast_stmt* stmt;
} stackItem;
typedef struct {
stackItem *item;
int size;
int top;
int maxTerm;
} Stack;
/**
* @param S - this is a stack to operate with.
* @return - returns ERROR_INTERNAL if there was a memory error, 0 if not
*
* Initialises the stack before the first use
*/
void stackInit(Stack *S);
/**
* @param S - this is a stack to operate with.
*
* Destroys the whole stack
*/
void stackDestroy(Stack *S);
/**
* @param S - this is a stack to operate with.
*
* Resize the stack size if the current stack reach it's maximum.
* The new stack size is always double as the previous one.
*/
void stackResize(Stack *S);
/**
* @param S - this is a stack to operate with.
* @return - true if stack is empty, false if it's not.
*/
bool stackEmpty(Stack *S);
/**
* @param S - this is a stack to operate with.
* @return - true if stack is full, false if it's not.
*/
bool stackFull(Stack *S);
/**
* Saves new pointer on the top of the stack.
* If the stack size is already full, resizes the stack by calling stackResize function and then saves the pointer.
*
* @param S
* @param ptr
* @param Exp
* @param Token
* @param symbol
*/
void stackPush(Stack *S, BinaryTreePtr *ptr, ast_exp *Exp, token *Token, precedStack symbol, ast_stmt* stmt);
/**
* @param S - this is a stack to operate with.
* @return - Returns the pointer that is on the top of the stack.
*
* Function also deletes the returned pointer from the stack.
*/
void stackPop(Stack *S);
/**
* Returns top of the stack on address of *item
*
* @param S
* @param item
*/
void stackTop(Stack *S, stackItem *item);
/**
* Returns terminal that is most top in stack and returns it on address of *item
*
* @param S
* @param item
*/
void stackTopTerminal(Stack *S, stackItem *item);
#endif //IFJ2017_STACK_H