-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecedence_stack_test.c
106 lines (92 loc) · 2.68 KB
/
precedence_stack_test.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
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
/***************************
* PROJECT:
* IFJ20 - Compiler for imperative programming language IFJ20
*
* UNIVERSITY:
* Faculty of Information Technology, Brno University of Technology
*
* FILE:
* precedence_stack_test.h
*
* DESCRIPTION:
* Prececence stack test
*
* AUTHORS:
* Kolaříková Mirka <[email protected]>
*/
#include "precedence_stack.h"
int main(){
printf("//----------------/ Create stack /------------------//\n");
struc_prec_stack *ptr = create_precStack(10);
string testStr;
strInit(&testStr);
struc_token *top;
int full = 0;
printf("\n");
printf("1.//----------------/ Push 1, test1 /------------------//\n");
strAddChars(&testStr, "test1");
full = push_precStack(ptr, 1, testStr);
if(full){
printf("ERROR: stack full\n");
exit(99);
}
print_precStack(ptr);
strClear(&testStr);
printf("\n");
printf("2.//----------------/ Push 2, test2 /------------------//\n");
strAddChars(&testStr, "test2");
full = push_precStack(ptr, 2, testStr);
if(full){
printf("ERROR: stack full\n");
exit(99);
}
print_precStack(ptr);
strClear(&testStr);
printf("\n");
printf("3.//--------------/ Push 4890, test4890 /---------------//\n");
strAddChars(&testStr, "test4890");
full = push_precStack(ptr, 4890, testStr);
if(full){
printf("ERROR: stack full\n");
exit(99);
}
print_precStack(ptr);
strClear(&testStr);
printf("\n");
printf("4.//------------------/ Stack top1 /-------------------//\n");
top = peek1_precStack(ptr);
printf("TOP1: {%d,%s}\n",top->tokenNum, top->tokenStr.str);
printf("\n");
printf("4.//------------------/ Stack top2 /-------------------//\n");
top = peek2_precStack(ptr);
printf("TOP2: {%d,%s}\n",top->tokenNum, top->tokenStr.str);
printf("\n");
printf("4.//------------------/ Stack top3 /-------------------//\n");
top = peek3_precStack(ptr);
printf("TOP3: {%d,%s}\n",top->tokenNum, top->tokenStr.str);
printf("\n");
printf("5.//----------------------/ Pop /----------------------//\n");
pop_precStack(ptr);
print_precStack(ptr);
printf("\n");
printf("4.//------------------/ Stack top3 - error /-------------------//\n");
top = peek3_precStack(ptr);
if(top == NULL){
printf("NULL - ERROR ok ");
}else{
printf("TOP3: {%d,%s}\n",top->tokenNum, top->tokenStr.str);
}
printf("\n");
printf("6.//-------------------/ Stack top /--------------------//\n");
top = peek1_precStack(ptr);
printf("TOP: {%d,%s}\n",top->tokenNum, top->tokenStr.str);
printf("\n");
printf("7.//---------------------/ Pop /----------------------//\n");
pop_precStack(ptr);
print_precStack(ptr);
printf("\n");
printf("8.//-----------------/ Free stack /------------------//\n");
free_precStack(ptr);
printf("\n");
return 0;
}