-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpret.hpp
More file actions
2646 lines (2490 loc) · 73.2 KB
/
interpret.hpp
File metadata and controls
2646 lines (2490 loc) · 73.2 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef _SQL_H_
#define _SQL_H_
#include "dbms.hpp"
#include <algorithm>
#include <cctype>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <unistd.h>
enum sql_exception_code
{
XW_like_in,
XW_like_str,
XW_log_rel,
XW_log_expr,
XW_in,
XW_long_br,
XW_long_lex,
XW_long_stol,
XW_long_expr,
XW_in_br,
XW_empty_lexer,
XW_lexer_nexist,
SE_nexist,
SE_expr,
CR_open,
CR_close,
CR_expr,
IS_open,
IS_close,
IS_expr,
IS_range,
DR_expr,
DL_expr,
UP_expr,
UP_nexist,
UP_eq,
UP_info,
UP_range,
expr
};
class SQL_Xception
{
public:
std::string Message;
void report();
SQL_Xception(sql_exception_code);
SQL_Xception(const std::string &aMessage) : Message(aMessage){};
SQL_Xception(const SQL_Xception &xception) : Message(xception.Message){};
~SQL_Xception() {}
};
void SQL_Xception::report()
{
std::cerr << Message << std::endl;
return;
};
SQL_Xception::SQL_Xception(sql_exception_code errcode)
{
switch (errcode)
{
case SE_nexist:
Message = "Error in the select sentenece: no such field";
break;
case SE_expr:
Message = "Error in the select sentenece: wrong expression";
break;
case CR_open:
Message = "Error in the create sentenece: expected opening bracket";
break;
case CR_close:
Message = "Error in the create sentenece: expected opening bracket";
break;
case CR_expr:
Message = "Error in the create sentenece: wrong expression";
break;
case IS_open:
Message = "Error in the insert sentenece: expected opening bracket";
break;
case IS_close:
Message = "Error in the insert sentenece: expected opening bracket";
break;
case IS_expr:
Message = "Error in the insert sentenece: wrong expression";
break;
case IS_range:
Message = "Error in the insert sentenece: text is too big to be inserted";
break;
case DR_expr:
Message = "Error in the drop sentenece: wrong expression";
break;
case DL_expr:
Message = "Error in the delete sentenece: wrong expression";
break;
case UP_expr:
Message = "Error in the update sentenece: wrong expression";
break;
case UP_nexist:
Message = "Error in the update sentenece: such field does not exist";
break;
case UP_eq:
Message = "Error in the update sentenece: wrong expression, expected '='";
break;
case UP_info:
Message = "Error in the update sentenece: can not get information about the field";
break;
case UP_range:
Message = "Error in the update sentenece: text is too big to be inserted";
break;
case XW_like_in:
Message = "Error in where clause: expected 'LIKE' or 'IN' word";
break;
case XW_like_str:
Message = "Error in where clause: expected string";
break;
case XW_log_rel:
Message = "Error in where clause: expected relation sign";
break;
case XW_log_expr:
Message = "Error in where clause: unknown logic expression";
break;
case XW_in:
Message = "Error in where clause: expected 'IN' word";
break;
case XW_long_br:
Message = "Error in where clause: expected closing bracket in the long expression";
break;
case XW_long_lex:
Message = "Error in where clause: unknown lexeme in the long expression";
break;
case XW_long_stol:
Message = "Error: error while converting string to long";
break;
case XW_long_expr:
Message = "Error in where clause: unknown expression";
break;
case XW_in_br:
Message = "Error in where clause: expected closing bracket in the IN-clause";
break;
case XW_empty_lexer:
Message = "Error in where clause (lexer where): empty string";
break;
case XW_lexer_nexist:
Message = "Error in where clause (lexer where): no such title in the table";
break;
case expr:
Message = "Error: unkown statement";
break;
default:
break;
}
};
// Interpreter --- SQL-interpreter class
class Interpreter
{
private:
void select_sentence(std::string &);
void insert_sentence(std::string &);
void update_sensence(std::string &);
void delete_sentence(std::string &);
void create_sentence(std::string &);
void drop_sentence(std::string &);
void field_description(std::string &);
std::vector<size_t> where_clause(std::string &);
ITable bd_table;
public:
Interpreter(std::string &);
~Interpreter() {}
};
/*-----------------------------------------------------------------------------------------------*/
// read one word and one symbol from line
std::string read_word(std::string &str, char separator = ' ')
{
std::string word;
int i = 0;
while (isspace(str.c_str()[i]) && !(str.empty()))
{
str.erase(0, 1);
}
while (!isspace(str.c_str()[i]) && !(str.empty()) && (str.c_str()[i] != separator))
{
word = word + str.c_str()[i];
str.erase(0, 1);
}
while (isspace(str.c_str()[i]) && !(str.empty()))
{
str.erase(0, 1);
}
return word;
}
// read one symbol from line
std::string read_symb(std::string &str)
{
std::string word;
word += str.c_str()[0];
str.erase(0, 1);
return word;
}
// change all constructions in string like "from" to constructions "to" (for tokenization)
void replace_all(std::string &str, const std::string &from, const std::string &to)
{
if (from.empty())
{
return;
}
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
return;
}
/*---------------------------------------- LONG_EXPR --------------------------------------------*/
/* lexical parser for long-expressions
LONG_EXPR = LONG_SUM { S_OP LONG_SUM }
S_OP = + | -
LONG_SUM = LONG_MULT { M_OP LONG_MULT }
M_OP = * | \ | %
LONG_MULT = LONG_VAL | (LONG_EXPR)
LONG_VAL = id | longint
*/
enum long_type_t
{
START,
PLUS, // +
MINUS, // -
MULT, // *
DIV, // /
MOD, // %
OPEN, // (
CLOSE, // )
NUMBER, // set of numbers
L_NAME, // name of the field with type LONG
END
};
namespace lexer_long_expr
{
enum long_type_t cur_lex_type; // type of a current lexem
std::string cur_lex_text; // previous lexem
std::string c; // current lexeme
// read first word, set current lexem type to START
void init(std::string &str)
{
c = read_word(str);
cur_lex_type = START;
}
// read next words and set new lexem type
void next(std::string &str)
{
cur_lex_text.resize(0);
long_type_t state = START;
while (state != END)
{
switch (state)
{
case START:
if (c == "+")
{
state = PLUS; // plus
}
else if (c == "-")
{
state = MINUS; // mius
}
else if (c == "*")
{
state = MULT; // multiply
}
else if (c == "/")
{
state = DIV; // div
}
else if (c == "%")
{
state = MOD; // mod
}
else if (c == "(")
{
state = OPEN; // open bracket
}
else if (c == ")")
{
state = CLOSE; // close bracket
}
// words, that can follow long-expression
else if ((c == "NOT") || (c == "IN") ||
(c == "WHERE") || (c == "=") ||
(c == ">") || (c == "<") ||
(c == ">=") || (c == "<=") ||
(c == "!=") || (c == "AND") ||
(c == "OR") || c.empty())
{
cur_lex_type = END;
state = END;
}
else
{
unsigned int i = 0;
state = NUMBER;
while ((i < c.length()))
{
if (!isdigit(c[i]))
{
// not long integer, maybe it is a long_name
i = c.length();
state = L_NAME;
}
i++;
}
}
break;
case PLUS:
cur_lex_type = PLUS;
state = END;
break;
case MINUS:
cur_lex_type = MINUS;
state = END;
break;
case MULT:
cur_lex_type = MULT;
state = END;
break;
case DIV:
cur_lex_type = DIV;
state = END;
break;
case MOD:
cur_lex_type = MOD;
state = END;
break;
case OPEN:
cur_lex_type = OPEN;
state = END;
break;
case CLOSE:
cur_lex_type = CLOSE;
state = END;
break;
case NUMBER:
cur_lex_type = NUMBER;
state = END;
break;
case L_NAME:
cur_lex_type = L_NAME;
state = END;
break;
case END:
break;
default:
break;
}
if (state != END)
{
if (cur_lex_type != END)
{
cur_lex_text = c;
}
c = read_word(str);
}
}
}
}
// syntactic parser for long-expressions
namespace parser_long_expr
{
// the number of the row in the table from which to insert the value in the expression
size_t line_to_check;
// read first word, set current lexem type to START
void init(std::string &str)
{
lexer_long_expr ::init(str);
lexer_long_expr ::next(str);
}
// functions for syntactic parser
std::string A(std::string &); // processes + | - (S_OP)
std::string B(std::string &); // processes * | / | % (M_OP) and LONG_SUM
std::string C(std::string &); // LONG_MULT, longint, LONG id and brackets (calls A())
// functions to calculate the value for each row in the table
long Al(std::string &, ITable &);
long Bl(std::string &, ITable &);
long Cl(std::string &, ITable &);
std::string A(std::string &str)
{
std::string s = B(str);
while ((lexer_long_expr::cur_lex_type == PLUS) || (lexer_long_expr::cur_lex_type == MINUS))
{
// LONG_SUM { S_OP LONG_SUM }
if (lexer_long_expr::cur_lex_type == PLUS)
{
lexer_long_expr::next(str);
s = s + "+ " + B(str);
}
else if (lexer_long_expr::cur_lex_type == MINUS)
{
lexer_long_expr::next(str);
s = s + "- " + B(str);
}
}
return s;
}
std::string B(std::string &str)
{
std::string s = C(str);
while ((lexer_long_expr::cur_lex_type == MULT) ||
(lexer_long_expr::cur_lex_type == DIV) ||
(lexer_long_expr::cur_lex_type == MOD))
{
// LONG_MULT { M_OP LONG_MULT }
if (lexer_long_expr::cur_lex_type == MULT)
{
lexer_long_expr::next(str);
s = s + "* " + C(str);
}
else if (lexer_long_expr::cur_lex_type == DIV)
{
lexer_long_expr::next(str);
s = s + "/ " + C(str);
}
else if (lexer_long_expr::cur_lex_type == MOD)
{
lexer_long_expr::next(str);
s = s + "% " + C(str);
}
}
return s;
}
std::string C(std::string &str)
{
std::string s;
if (lexer_long_expr::cur_lex_type == OPEN) // LONG_MULT = '(' LONG_EXPR ')'
{
lexer_long_expr::next(str);
s = "( " + A(str);
if (lexer_long_expr::cur_lex_type != CLOSE)
{
throw SQL_Xception(XW_long_br);
}
s = s + ") ";
lexer_long_expr::next(str);
}
else if (lexer_long_expr::cur_lex_type == NUMBER) // LONG_MULT = longint
{
s = lexer_long_expr::cur_lex_text + " ";
lexer_long_expr::next(str);
}
else if (lexer_long_expr::cur_lex_type == L_NAME) // LONG_MULT = id
{
s = lexer_long_expr::cur_lex_text + " ";
lexer_long_expr::next(str);
}
else
{
throw SQL_Xception(XW_long_lex);
}
return s;
}
long Al(std::string &str, ITable &line)
{
long num = parser_long_expr::Bl(str, line);
while ((lexer_long_expr::cur_lex_type == PLUS) ||
(lexer_long_expr::cur_lex_type == MINUS))
{
if (lexer_long_expr::cur_lex_type == PLUS)
{
lexer_long_expr::next(str);
num = num + parser_long_expr::Bl(str, line);
}
else if (lexer_long_expr::cur_lex_type == MINUS)
{
lexer_long_expr::next(str);
num = num - parser_long_expr::Bl(str, line);
}
}
return num;
}
long Bl(std::string &str, ITable &line)
{
long num = parser_long_expr::Cl(str, line);
while ((lexer_long_expr::cur_lex_type == MULT) ||
(lexer_long_expr::cur_lex_type == DIV) ||
(lexer_long_expr::cur_lex_type == MOD))
{
if (lexer_long_expr::cur_lex_type == MULT)
{
lexer_long_expr::next(str);
num = num * parser_long_expr::Cl(str, line);
}
else if (lexer_long_expr::cur_lex_type == DIV)
{
lexer_long_expr::next(str);
num = num / parser_long_expr::Cl(str, line);
}
else if (lexer_long_expr::cur_lex_type == MOD)
{
lexer_long_expr::next(str);
num = num % parser_long_expr::Cl(str, line);
}
}
return num;
}
long Cl(std::string &str, ITable &line)
{
long num = 0;
if (lexer_long_expr::cur_lex_type == OPEN)
{
lexer_long_expr::next(str);
num = parser_long_expr::Al(str, line);
if (lexer_long_expr::cur_lex_type != CLOSE)
{
throw SQL_Xception(XW_long_br);
}
lexer_long_expr::next(str);
}
else if (lexer_long_expr::cur_lex_type == NUMBER)
{
try
{
// convert string to long
num = stol(lexer_long_expr::cur_lex_text);
}
catch (...)
{
throw SQL_Xception(XW_long_stol);
}
lexer_long_expr::next(str);
}
else if (lexer_long_expr::cur_lex_type == L_NAME)
{
// get value from the table
num = line.GetLongField(lexer_long_expr::cur_lex_text, line_to_check);
lexer_long_expr::next(str);
}
else
{
throw SQL_Xception(XW_long_lex);
}
return num;
}
}
/*--------------------------------------- WHERE-CLAUSE ------------------------------------------*/
/* lexical parser for where-clause
WHERE = 'WHERE' TEXT_ID ['NOT'] 'LIKE' STR | EXPR ['NOT'] 'IN' (CONSTS) | 'WHERE' LOG | 'WHERE ALL'
*/
enum where_type_t
{
START_w,
PLUS_w, // +
MINUS_w, // -
OR_w, // OR
MULT_w, // *
DIV_w, // /
MOD_w, // %
AND_w, // AND
NOT_w, // NOT
OPEN_w, // (
CLOSE_w, // )
REL_w, // =, >, <, !=, >=, <=
NUMBER_w, // set of numbers
L_NAME_w, // name of the field with the type LONG
T_NAME_w, // name of the field with the type TEXT
STR_w, // line
LIKE_w, // LIKE
IN_w, // IN
COM_w, // ,
ALL_w, // ALL
END_w
};
namespace lexer_where
{
enum where_type_t cur_lex_type_w;
std::string cur_lex_text_w;
std::string c_w;
// read first word, set current lexem type to START_w
void init(std::string &str)
{
c_w = read_word(str);
cur_lex_type_w = START_w;
}
void next(std::string &str, ITable bd)
{
cur_lex_text_w.resize(0);
where_type_t state_w = START_w;
while (state_w != END_w)
{
switch (state_w)
{
case START_w:
if (c_w == "+")
{
state_w = PLUS_w;
}
else if (c_w == "-")
{
state_w = MINUS_w;
}
else if (c_w == "OR")
{
state_w = OR_w;
}
else if (c_w == "*")
{
state_w = MULT_w;
}
else if (c_w == "/")
{
state_w = DIV_w;
}
else if (c_w == "%")
{
state_w = MOD_w;
}
else if (c_w == "AND")
{
state_w = AND_w;
}
else if (c_w == "NOT")
{
state_w = NOT_w;
}
else if (c_w == "(")
{
state_w = OPEN_w;
}
else if (c_w == ")")
{
state_w = CLOSE_w;
}
else if ((c_w == "=") || (c_w == "!=") ||
(c_w == ">") || (c_w == ">=") ||
(c_w == "<") || (c_w == "<="))
{
state_w = REL_w;
}
else if (c_w == "LIKE")
{
state_w = LIKE_w;
}
else if (c_w == "IN")
{
state_w = IN_w;
}
else if (c_w == ",")
{
state_w = COM_w;
}
else if (c_w == "ALL")
{
state_w = ALL_w;
}
else if (c_w.empty())
{
cur_lex_type_w = END_w;
state_w = END_w;
}
else // number, text field's title or long field's title
{
unsigned int i = 0;
bool flag_long = 1;
while ((i < c_w.length()) && flag_long)
{
if (!isdigit(c_w[i]))
flag_long = 0; // not long
i++;
}
if (flag_long)
state_w = NUMBER_w;
else if (c_w[0] == '\'') // line
{
state_w = STR_w;
if (c_w[c_w.length() - 1] == '\'')
{
cur_lex_type_w = STR_w;
cur_lex_text_w = cur_lex_text_w + c_w + " ";
c_w = read_word(str);
state_w = END_w;
}
}
else
{
// check if the word is the field and its type
Type t;
try
{
t = bd.GetFieldType(c_w);
}
catch (...)
{
throw SQL_Xception(XW_lexer_nexist);
}
if (t == TEXT)
state_w = T_NAME_w;
else
state_w = L_NAME_w;
}
}
break;
case PLUS_w:
cur_lex_type_w = PLUS_w;
state_w = END_w;
break;
case MINUS_w:
cur_lex_type_w = MINUS_w;
state_w = END_w;
break;
case OR_w:
cur_lex_type_w = OR_w;
state_w = END_w;
break;
case MULT_w:
cur_lex_type_w = MULT_w;
state_w = END_w;
break;
case DIV_w:
cur_lex_type_w = DIV_w;
state_w = END_w;
break;
case MOD_w:
cur_lex_type_w = MOD_w;
state_w = END_w;
break;
case AND_w:
cur_lex_type_w = AND_w;
state_w = END_w;
break;
case NOT_w:
cur_lex_type_w = NOT_w;
state_w = END_w;
break;
case OPEN_w:
cur_lex_type_w = OPEN_w;
state_w = END_w;
break;
case CLOSE_w:
cur_lex_type_w = CLOSE_w;
state_w = END_w;
break;
case REL_w:
cur_lex_type_w = REL_w;
state_w = END_w;
break;
case NUMBER_w:
cur_lex_type_w = NUMBER_w;
state_w = END_w;
break;
case L_NAME_w:
cur_lex_type_w = L_NAME_w;
state_w = END_w;
break;
case T_NAME_w:
cur_lex_type_w = T_NAME_w;
state_w = END_w;
break;
case STR_w:
// searching fot the line end
if (c_w.empty())
{
throw SQL_Xception(XW_empty_lexer);
}
if (c_w[c_w.length() - 1] == '\'') // otherwise stay in START_w
{
cur_lex_type_w = STR_w;
cur_lex_text_w = cur_lex_text_w + c_w + " ";
c_w = read_word(str);
state_w = END_w;
}
break;
case LIKE_w:
cur_lex_type_w = LIKE_w;
state_w = END_w;
break;
case IN_w:
cur_lex_type_w = IN_w;
state_w = END_w;
break;
case COM_w:
cur_lex_type_w = COM_w;
state_w = END_w;
break;
case ALL_w:
cur_lex_type_w = ALL_w;
state_w = END_w;
break;
case END_w:
break;
default:
break;
}
if (state_w != END_w)
{
// read a new word for the future analyses
if (cur_lex_type_w != END_w)
{
cur_lex_text_w = cur_lex_text_w + c_w + " ";
}
c_w = read_word(str);
}
}
}
}
// modes of where_clause
enum mode_type
{
LIKE_alt, // 'WHERE' TEXT_ID ['NOT'] 'LIKE' STR |
IN_alt_T, // 'WHERE' TEXT_EXPR ['NOT'] 'IN' (CONSTS)
IN_alt_L, // 'WHERE' LONG_EXPR ['NOT'] 'IN' (CONSTS)
LOG_alt, // 'WHERE' LOG
ALL_alt // 'WHERE' 'ALL'
};
// syntactic parser for where-clause
namespace parser_where
{
size_t line_to_check;
bool flag_log = 0;
bool flag_expr = 0;
enum mode_type mode;
std::multiset<long> mst_l; // list of long constants
std::multiset<std::string> mst_s; // list of string constants
void init(std::string &str, ITable bd)
{
lexer_where ::init(str); // c_w = read_word(str); cur_lex_type_w = START_w;
lexer_where ::next(str, bd);
}
// functions for sintactic parser
std::string W0(std::string &, ITable &); // beginning of where-clause
std::string W1(std::string &, ITable &); // LIKE-alternative
std::string W2(std::string &, ITable &); // IN-alternative
std::string W3(std::string &, ITable &); // start processing long or logic expressions, call W4
std::string W4(std::string &, ITable &); // long or logic expressions, call W5 or W7
std::string W5(std::string &, ITable &); // long or logic expressions, call W3 (if in brackets), W6 or W7
std::string W6(std::string &, ITable &); // parsing text expression and relations for logic-expr
std::string W7(std::string &, ITable &); // brackets, call W3
void W8(std::string &, ITable &); // list of constants
// functions to calculate the value of logic-expression
long W31(std::string &, ITable &); // start funstion
long W41(std::string &, ITable &);
long W51(std::string &, ITable &);
long W71(std::string &, ITable &); // brackets
std::string W0(std::string &str, ITable &bd)
{
std::string s;
if (lexer_where::cur_lex_type_w == ALL_w)
{
s = "ALL";
mode = ALL_alt;
lexer_where::next(str, bd);
}
else if (lexer_where::cur_lex_type_w == T_NAME_w)
{
// if the first word is name of the TEXT field, it can be LIKE, LOG or IN-alternative
s = lexer_where::cur_lex_text_w;
lexer_where::next(str, bd);
if (lexer_where::cur_lex_type_w == NOT_w) // if there is the word "NOT"
{
s = s + lexer_where::cur_lex_text_w;
lexer_where::next(str, bd);
}
if (lexer_where::cur_lex_type_w == LIKE_w)
{
s = s + lexer_where::cur_lex_text_w;
lexer_where::next(str, bd);
// processing of LIKE-alternative
s = s + W1(str, bd);
}
else if (lexer_where::cur_lex_type_w == IN_w)
{
s = s + lexer_where::cur_lex_text_w;
mode = IN_alt_T;
// processing of IN-alternative
s = s + W2(str, bd);
}
else
{
throw SQL_Xception(XW_like_in);
}
}
else if (lexer_where::cur_lex_type_w == STR_w)
{
// the first word is a line, maybe IN-alternative (it is the text-expr)
s = lexer_where::cur_lex_text_w;
lexer_where::next(str, bd);
if (lexer_where::cur_lex_type_w == NOT_w) // if there is the word "NOT"
{
s = s + lexer_where::cur_lex_text_w;
lexer_where::next(str, bd);
}
if (lexer_where::cur_lex_type_w == IN_w)
{
s = s + lexer_where::cur_lex_text_w;
mode = IN_alt_T;
// processing of IN-alternative
s = s + W2(str, bd);
}
else
{
throw SQL_Xception(XW_in);
}
}
else if ((lexer_where::cur_lex_type_w == L_NAME_w) || (lexer_where::cur_lex_type_w == NUMBER_w))
{
// the first word is a set of numbers or name of the field with type LONG,
// it can be IN-alternative (the beginning of long-expr)
str.insert(0, lexer_where::cur_lex_text_w);
lexer_where::c_w += " ";
str.insert(lexer_where::cur_lex_text_w.length(), lexer_where::c_w);
// processing of long-expression
parser_long_expr::init(str);
s = parser_long_expr::A(str);
// if the expression is not right
if (lexer_long_expr::cur_lex_type != END)
{
throw SQL_Xception(XW_long_expr);
}
s = s + " ";
lexer_where::c_w = lexer_long_expr::c;
lexer_where::next(str, bd);
if (lexer_where::cur_lex_type_w == NOT_w)
{