-
Notifications
You must be signed in to change notification settings - Fork 2
/
keyKalau.h
134 lines (111 loc) · 2.97 KB
/
keyKalau.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
132
133
// Bahasa Anak Indonesia untuk Komputer - BAIK
// Copyright Haris Hasanudin - 2005 - 2010
//
// Kupersembahkan untuk istriku tercinta Masako, anakku tersayang Takumi
// dan Tomoki serta seluruh putra putri Indonesia
void keyKalau ()
{
VAL_LABEL valdat;
int num_kalau=0;
int num_akhirkalau=0;
memset(&valdat, '\0', sizeof(valdat));
if_deep++;
valdat = expression();
//printf("KALAU cond val %d\n", valdat.val);
if( valdat.val ){
// printf("condit OK\n");
currKalauResult[if_deep] = 1;
do{
getlex();
}while( lex.type != _MAKA && lex.type != _EOF );
if( lex.type == _EOF )
Error("KALAU tanpa MAKA");
}
else{
// printf("condit false\n");
currKalauResult[if_deep] = 0;
do{
getlex();
if( lex.type == _KALAU ) {
num_kalau++;
if_deep++;
}
if( lex.type == _STOPKALAU ) {
num_akhirkalau--;
if_deep--;
}
// printf("lex %s\n", lex.detail.string);
// printf("num kalau %d\n", num_kalau);
// printf("num akhir %d\n", num_akhirkalau);
if(num_kalau != num_akhirkalau && num_kalau >=0 && num_akhirkalau >= 0) {
// there is kalau inside kalau
do {
getlex();
}while( lex.type != _STOPKALAU && lex.type != _EOF );
ungetlex();
}
}while( (lex.type != _STOPKALAU ) &&
lex.type != _KELUARSELAGI &&
lex.type != _KELUARUNTUK &&
lex.type != _LANJUT &&
lex.type != _LAINNYA &&
lex.type != _LAINKALAU &&
lex.type != _EOF );
// printf("type %d\n", lex.type);
if( lex.type == _EOF )
Error("KALAU tanpa STOPKALAU");
}
if(lex.type == _LAINKALAU)
ungetlex();
}
void keyLainKalau ()
{
VAL_LABEL valdat;
int num_kalau=0;
int num_akhirkalau=0;
memset(&valdat, '\0', sizeof(valdat));
valdat = expression();
// printf("cond val %d\n", valdat.val);
if( valdat.val ){
// condit OK
currKalauResult[if_deep] = 1;
do{
getlex();
}while( lex.type != _MAKA && lex.type != _EOF );
if( lex.type == _EOF )
Error("LAINKALAU tanpa MAKA");
}
else{
// condit NG
currKalauResult[if_deep] = 0;
do{
getlex();
if( lex.type == _KALAU ) {
num_kalau++;
if_deep++;
}
if( lex.type == _STOPKALAU ) {
num_akhirkalau--;
if_deep--;
}
if(num_kalau != num_akhirkalau && num_kalau >= 0 && num_akhirkalau >= 0) {
// there is kalau inside lainkalau
do {
getlex();
}while( lex.type != _STOPKALAU && lex.type != _EOF );
ungetlex();
}
}while( (lex.type != _STOPKALAU ) &&
lex.type != _KELUARSELAGI &&
lex.type != _KELUARUNTUK &&
lex.type != _LANJUT &&
lex.type != _LAINNYA &&
lex.type != _LAINKALAU &&
lex.type != _EOF );
if( lex.type == _EOF )
Error("KALAU tanpa STOPKALAU");
}
if(lex.type == _LAINNYA || lex.type == _LAINKALAU) {
ungetlex();
}
}