-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathissues.txt
273 lines (203 loc) · 5.94 KB
/
issues.txt
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#Known bugs
2) Return value of a void function
previously we were checking the last token in the list so if it wasn't return we were adding "return nil", but following function showed that this is a wrong approach
f = fun(a,b)
if(a == b)
return ""
end
end
this function won't return anything if a != b, will create recursion...
3) String format cannot work for more than one value
"fbg %d c" % 3 will work but "f %d %d "% (3,4) won't work
4) empty if-end blocks create problem in the parser. The connection of the "if" object in the main list cannot be done
Try to see the error
if(3);end #this is problematic
if(3);x;end #this is ok
+) Lexer has a bug : format was read as "for" and mat words
--Solved
!b metachar is added to solve boundary problems for words
New location finding algorithm, now we can detect which part in the given regex pattern is catched
+) | | operator has precedence issues, check this
if(|a|-1 != |b|)
do smt
end
--Solved
But we have changed the precedence of pipe operator,which result to unexpected behaviors
this should be noted.
Should we make the same precedence for all logical operators ?
+)
Parser crashes for unary operators.
check this
y = x*-x
will not exactly y = x*(-x)
--Solved
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
typedef struct pair{
char * name;
int value;
}pair;
typedef struct hashtable{
pair * kv_list;
int cap;
int len;
}hashtable;
hashtable * new_hashtable(int cap){
hashtable * ht = (hashtable * )malloc(sizeof(hashtable));
ht->kv_list = (pair *)calloc(cap,sizeof(pair));
ht->cap = cap;
ht->len = 0;
return ht;
}
void resize_hashtable(hashtable * ht){
ht->cap <<= 1;
ht->kv_list = (pair *) realloc(ht->kv_list,sizeof(pair)*ht->cap);
assert(ht->kv_list != NULL);
}
void print_hashtable(hashtable * ht){
printf("Table capacity :%d | table->len %d\n",ht->cap,ht->len);
for (int i = 0; i < ht->cap; ++i){
pair * p = &ht->kv_list[i];
if(p->name != NULL)
printf("(%d)['%s'] = %d\n",i,p->name,p->value);
}
}
size_t hash(const char *str, int bucket_size){
unsigned long hash = 5381;
int c;
while (c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash & (bucket_size - 1);
}
void ht_insert(hashtable * ht, const char * key, int value){
int index = hash(key,ht->cap);
printf("Insertion [%s] location is %d\n",key,index);
pair * p = &ht->kv_list[index];
if(p->name == NULL){
printf("Empty slot found, inserting here\n");
p->name = strdup(key);
p->value = value;
}
else{
printf("Slot is filled, now probing\n");
if(strcmp(key,p->name) == 0){
printf("Slot is ours just change the value\n");
p->value = value;
return;
}else{
//now insertion must be found in another location but first check the size
if(ht->len == ht->cap-1){
assert(0);
}
int tries = 0;
while(p->name != NULL && tries <= 5){
index = ++index & (ht->cap-1);
p = &ht->kv_list[index];
printf("Trying index = %d\n",index);
++tries;
}
if(p->name == NULL){
printf("Location found at %d, inserting here\n",index);
p->name = strdup(key);
p->value = value;
}else{
printf("\n___Resizing hash table___\n");
resize_hashtable(ht);
ht_insert(ht,key,value);
//printf("Resize the hashtable...Exiting! tried %d times\n",tries);
//exit(1);
}
}
}
++(ht->len);
printf("=============================\n");
}
void ht_remove_key(hashtable * ht, const char * key){
int index = hash(key,ht->cap);
printf("Removing [%s] location is %d\n",key,index);
pair * p = &ht->kv_list[index];
if(p->name == NULL) return; //nothing to remove ? is it really ?
int tries = 0;
while(p->name != NULL && tries <= 5 && strcmp(key,p->name) != 0){
index = ++index & (ht->cap-1);
p = &ht->kv_list[index];
printf("Is this our slot given key['%s'] founded ['%s']\n",key,p->name);
}
if(tries <= 5){
if(p->name == NULL) return;
//so found the string
printf("Key is found at %d, removing succesfully\n",index);
free(p->name);
p->name = NULL;
}
else{
assert(0);
}
}
int ht_lookup(hashtable * ht, const char * key){
int index = hash(key,ht->cap);
printf("Lookup [%s] location is %d\n",key,index);
pair * p = &ht->kv_list[index];
int tries = 0;
while(p->name != NULL && tries <= 5 && strcmp(key,p->name) != 0){
index = ++index & (ht->cap-1);
p = &ht->kv_list[index];
printf("Is this our slot given key['%s'] founded ['%s']\n",key,p->name);
}
if(tries <= 5 && p->name != NULL){
printf("Key['%s']:%d is founded returning value\n",p->name,p->value);
return p->value;
}
else{
printf("Table does not contain this key, raise an error!\n");
assert(0);
}
}
int main(){
/*const char * names[] = {
"hello","basar","x","y","x2","hello1","fbgencer","deneme","fbgc","sublime","python","gcc"
};
int name_len = sizeof(names)/sizeof(names[0]);
printf("name_len :%d\n",name_len );
for (int i = 0; i < name_len; ++i){
printf("[%s] = %lu\n",names[i],hash(names[i],32));
}*/
hashtable * ht = new_hashtable(16);
FILE * fp = fopen('dictionary.txt','r');
while(fp != EOF){
char buf[100];
int sz = 100;
getline(buf,&sz,fp);
}
/*
ht_insert(ht,"fbgencer",8);
ht_insert(ht,"Nevsehir",100);
ht_insert(ht,"lord of the rings",102);
ht_insert(ht,"hello",1);
ht_insert(ht,"my name is basar",104214);
ht_insert(ht,"x0",0);
ht_insert(ht,"x1",-34);
ht_insert(ht,"x2",-35);
ht_insert(ht,"x3",-36);
ht_insert(ht,"x4",-37);
ht_insert(ht,"fbgencer",-37);
ht_insert(ht,"ahmet",1223);
ht_insert(ht,"xxyez",5555);
ht_insert(ht,"dodiyez",303);
ht_insert(ht,"msi",102);
ht_insert(ht,"vatantatatan",10);
ht_insert(ht,"holeespanole",0);
ht_insert(ht,"fikret",1);
ht_insert(ht,"fikret3",3);
ht_insert(ht,"neth",885);
ht_insert(ht,"the good place",1202);
ht_insert(ht,"imdb",12);
ht_insert(ht,"twitter",1333);
ht_insert(ht,"sokaga cikma yasagi",96749);
print_hashtable(ht);
printf("Lookup %d\n",ht_lookup(ht,"xxyez") );*/
return 0;
}