-
Notifications
You must be signed in to change notification settings - Fork 0
/
symstack.h
96 lines (81 loc) · 2.06 KB
/
symstack.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
/**
* Project: Compiler for IFJ21 language
*
* Brief: Symbol stack
*
* Author: Stepan Bakaj <[email protected]>
*
* Date: 15-11-2021
*/
#ifndef IFJ_BRATWURST2021_SYMSTACK_H
#define IFJ_BRATWURST2021_SYMSTACK_H
#include "psa.h"
#include "data_types.h"
/**
* @struct Stack item represetation.
*/
typedef struct stack_item
{
psa_table_symbol_enum symbol; /// Symbol of stack item.
data_type_t data; /// Data type used for semantic analysis.
struct stack_item *next; /// Pointer to next stack item.
} sym_stack_item;
/**
* @struct Stack representation.
*/
typedef struct
{
sym_stack_item *top;
} sym_stack;
/**
* Function initializes stack.
*
* @param stack Pointer to stack.
*/
void sym_stack_init(sym_stack *stack);
/**
* Function pushes symbol to stack and sets its data type.
*
* @param stack Pointer to stack.
* @param symbol Symbol to be pushed.
* @param data Data types.
* @return True if successfull else false.
*/
bool symbol_stack_push(sym_stack* stack, psa_table_symbol_enum symbol, data_type_t data);
/**
* Function pops top symbol from stack.
*
* @param stack Pointer to stack.
* @return True if successfull else false.
*/
bool symbol_stack_pop(sym_stack* stack);
/**
* Function returns top termial.
*
* @param stack Pointer to stack.
* @return Returns pointer to top terminal.
*/
sym_stack_item* symbol_stack_top_terminal(sym_stack* stack);
/**
* Function inserts symbol after top terminal.
*
* @param stack Pointer to stack.
* @param symbol Symbol to be pushed.
* @param data Data types.
* @return True if successfull else false.
*/
bool symbol_stack_insert_after_top_terminal(sym_stack* stack, psa_table_symbol_enum symbol, data_type_t data);
/**
* Function returns top symbol.
*
* @param stack Pointer to stack.
* @return Pointer to symbol on top of stack.
*/
sym_stack_item* symbol_stack_top(sym_stack* stack);
/**
* Function frees resources used for stack.
*
* @param stack Pointer to stack.
*/
void symbol_stack_free(sym_stack* stack);
#endif //IFJ_BRATWURST2021_SYMSTACK_H