-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecedence_stack.h
131 lines (116 loc) · 2.57 KB
/
precedence_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/***************************
* PROJECT:
* IFJ20 - Compiler for imperative programming language IFJ20
*
* UNIVERSITY:
* Faculty of Information Technology, Brno University of Technology
*
* FILE:
* precedence_stack.h
*
* DESCRIPTION:
* Header file for stack used in precedence analisis
*
* AUTHORS:
* Kolaříková Mirka <xkolar76@stud.fit.vutbr.cz>
*/
#ifndef PREC_STACK
#define PREC_STACK
#include <stdio.h>
#include "str.h"
/**
* @struct structure representing one token
*
* @param tokenNum token number
* @param tokenStr token content
*/
typedef struct{
int tokenNum;
string tokenStr;
}struc_token;
/**
* @struct structure representing stack
*
* @param maxsize max set size of stack
* @param top top index
*/
typedef struct{
int maxsize;
int top;
struc_token *token;
}struc_prec_stack;
/**
* @brief creates new stack of specific size, returns pointer
*
* @param size set max size
*
* @return pointer to crated stack
*/
struc_prec_stack* create_precStack(int size);
/**
* @brief safely frees stack and its data
*
* @param stackPtr pointer to stack
*/
void free_precStack(struc_prec_stack *stackPtr);
/**
* @brief returns size of stack at the moment
*
* @param stackPtr pointer to stack
*
* @return size of stack at the moment
*/
int size_precStack(struc_prec_stack *stackPtr);
/**
* @brief check if stack is empty
*
* @param stackPtr pointer to stack
*
* @return 1 if empty
* 0 if not empty
*/
int isEmpty_precStack(struc_prec_stack *stackPtr);
/**
* @brief check if stack is full
*
* @param stackPtr pointer to stack
*
* @return 1 if full
* 0 if not full
*/
int isFull_precStack(struc_prec_stack *stackPtr);
/**
* @brief returns pointer to token at top
*
* @param stackPtr pointer to stack
*
* @return pointer to token at top
* Null if empty
*/
struc_token* peek1_precStack(struc_prec_stack *stackPtr);
struc_token* peek2_precStack(struc_prec_stack *stackPtr);
struc_token* peek3_precStack(struc_prec_stack *stackPtr);
/**
* @brief adds new token (tokenNum, tokenStr) to stack top
*
* @param stackPtr pointer to stack
* @param num defined token number
* @param string token content
*
* @return 0 if succes
* 1 if fail
*/
int push_precStack(struc_prec_stack *stackPtr, int num, string content);
/**
* @brief pops token at the stack top
*
* @param stackPtr pointer to stack
*/
void pop_precStack(struc_prec_stack *stackPtr);
/**
* @brief prints stack at format BOTTOM [{,}] TOP
*
* @param stackPtr pointer to stack
*/
void print_precStack(struc_prec_stack *stackPtr);
#endif