-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodified.c
More file actions
1612 lines (1438 loc) · 40.7 KB
/
modified.c
File metadata and controls
1612 lines (1438 loc) · 40.7 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
// © 2017 All Rights Reserved
// Group Number: 12
// Group Member_1: Chetna Warkade
// Group Member_2: Rahul Kant
// Group Member_3: Subham Gupta
// Group Member_4: Sidhharth Khabia
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// global varibles
const char *keyword[61] = {"add","all","as","alter","and","any","asc","avg","by","char","character" ,"column",
"create","cascade","constraints","date","distinct","double","default","delete","desc","drop","exists","foreign",
"float","from","group","having","in","index","insert","into","is","int","integer","join","key","left","like",
"max","min","not","null","or","order","outer","references","right","schema","select","set","smallint","sum",
"table","union","unique","update","value","values","varchar","where"};
const char *operator[11] = {"*","+","-","/",".","=","<",">","<>",">=","<="};
// structure
struct node
{
char *name;
int csize;
struct node *next[100];
};
char error[400];
char *p[100];
int parse_point;
// function declaration
int start();
int line();
int line1();
int line2();
int line3();
int line4();
int line5();
int line6();
int line7();
int line8();
int line9();
int line10();
int sline();
int sline1();
int sline2();
int sline3();
int sline4();
int ao();
int com();
int num();
int using();
int condition();
int new_condition();
int pro_condition();
int new_line();
int nes2();
int t_token();
int id();
int items();
int new_items();
int alpha_items();
int new_alpha_items();
int hyper_items();
int create_items();
int new_hyper_items();
int p_create_items();
int up_cond();
int new_up_cond();
int pp();
int isind();
int iskeyword();
int isval();
char *p1,*p2,*p3,*s;
//---------------------------parse tree printing in sentnetial form funtions start------------------------------//
// int indd = 0;
// printer function: prints the final sentnetial form
int strf(char **p1,char **p2)
{
int i,j,ret=-1;
for(i=0;i<strlen(*p2);i++)
{
if((*p2)[i]==(*p1)[0])
{
ret = i;
for(j=0;j<strlen(*p1);j++)
{
if((*p1)[j]!=(*p2)[j+i])
{
ret=-1;
break;
}
}
if(ret==i)
{
return ret;
}
}
}
return -1;
}
// srp function for sentnetial form
void srp(char **p1,char **p2,char **p3)
{
int n =strlen(*p2)-strlen(*p1)+strlen(*p3)+1;
// printf("%d\n",n );
int ind = strf(p1,p2);
// printf("%d\n",ind);
char ret[n];
int i;
// printf("1\n");
for(i=0;i<n-1;i++)
{
if(i<ind)
{
ret[i]=(*p2)[i];
}
else if(i<ind + strlen(*p3))
{
ret[i]=(*p3)[i-ind];
}
else
{
ret[i] = (*p2)[i-strlen(*p3)+strlen(*p1)];
}
}
ret[n-1]='\0';
//write code here
s = (char *)malloc(n*sizeof(char));
int l;
for(l=0;l<n;l++)
{
s[l]=ret[l];
}
(*p2) = s;
printf("%s\n",*p2 );
return;
}
// for printing tree
void printer (struct node **n)
{
if((*n)->csize==0)
{
return;
}
else
{
// printf("innnn\n");
// printf("%d\n",(*n)->csize );
printf("Production :%s ->",(*n)->name);
p1 = (*n)->name;
int i;
int indd=0;
char sss[500];
for(i=0;i<(*n)->csize;i++) // for that stage
{
int k;
for(k=0;k<strlen((*n)->next[i]->name);k++)
{
sss[k+indd]=((*n)->next[i]->name)[k];
}
indd+= strlen((*n)->next[i]->name);
sss[indd]=' ';
indd++;
printf("%s ",(*n)->next[i]->name);
}
printf("\n");
sss[indd-1]='\0';
// printf("p1 is :%s\n",p1 );
// printf("ye hamne banai h :%s\n",sss);
printf("%s-> ",p2 );
p3 = sss;
srp(&p1,&p2,&p3);
for(i=0;i<(*n)->csize;i++)
{
printer(&((*n)->next[i])); // recursive childs
}
}
}
//---------------------------parse tree printing in sentnetial form funtions end------------------------------//
//-------------------------------------------------------------------------------------------------------------//
//----------------------parser funtions start----------------------------------//
// start function : start
// start state
// start: line | sline | line start | sline start;
int start(struct node **n)
{
int s_point = parse_point;
struct node *no = NULL , *n2=NULL;
// goes to line
if(line(&no))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "start";
(*n)->next[0] = no;
(*n)->csize = 1;
return 1;
}
parse_point = s_point;
// goes to sline
if(sline(&n2))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "start";
(*n)->next[0] = n2;
(*n)->csize = 1;
return 1;
}
parse_point = s_point;
return 0;
}
// line function
int line(struct node **n)
{
// storing pointer for backward
int l_point = parse_point;
struct node *line1p, *line2p, *line3p, *line4p, *line5p, *line6p, *line7p, *line8p, *line9p, *line10p;
// 10 particular productions emanating from line
// line 1
if(line1(&line1p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line1p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 2
if(line2(&line2p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line2p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 3
if(line3(&line3p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line3p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 4
if(line4(&line4p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line4p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 5
if(line5(&line5p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line5p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 6
if(line6(&line6p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line6p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 7
if(line7(&line7p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line7p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 8
if(line8(&line8p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line8p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 9
if(line9(&line9p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line9p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
// line 10
if(line10(&line10p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line";
(*n)->next[0] = line10p;
(*n)->csize = 1;
return 1;
}
parse_point = l_point;
return 0;
}
// sline function
int sline(struct node **n)
{
int sl_point = parse_point;
struct node *sline1p, *sline2p, *sline3p, *sline4p;
// 4 productions emanating from sline function
// sline 1
if(sline1(&sline1p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline";
(*n)->next[0] = sline1p;
(*n)->csize = 1;
return 1;
}
parse_point = sl_point;
// sline 2
if(sline2(&sline2p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline";
(*n)->next[0] = sline2p;
(*n)->csize = 1;
return 1;
}
parse_point = sl_point;
// sline 3
if(sline3(&sline3p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline";
(*n)->next[0] = sline3p;
(*n)->csize = 1;
return 1;
}
parse_point = sl_point;
// sline 4
if(sline4(&sline4p)==1)
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline";
(*n)->next[0] = sline4p;
(*n)->csize = 1;
return 1;
}
parse_point = sl_point;
return 0;
}
// sline 1 production
// SELECT items FROM IDENTIFIER semi
int sline1(struct node **n)
{
struct node *selectp, *itemsp, *fromp, *idp, *colp;
if(t_token("select",&selectp) && items(&itemsp) && t_token("from",&fromp) && id(&idp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline1";
(*n)->next[0] = selectp;
(*n)->next[1] = itemsp;
(*n)->next[2] = fromp;
(*n)->next[3] = idp;
(*n)->next[4] = colp;
(*n)->csize = 5;
return 1;
}
return 0;
}
// sline 2 production
// SELECT items using pro_condition semi
int sline2(struct node **n)
{
struct node *selectp, *itemsp, *usingp, *pro_condp, *colp;
if(t_token("select",&selectp) && items(&itemsp) && using(&usingp) && pro_condition(&pro_condp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline2";
(*n)->next[0] = selectp;
(*n)->next[1] = itemsp;
(*n)->next[2] = usingp;
(*n)->next[3] = pro_condp;
(*n)->next[4] = colp;
(*n)->csize = 5;
return 1;
}
return 0;
}
// sline 3
// SELECT '*' FROM IDENTIFIER semi
int sline3(struct node **n)
{
struct node *selectp, *starp, *fromp, *idp, *colp;
if(t_token("select",&selectp) && t_token("*", &starp) && t_token("from", &fromp) && id(&idp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline3";
(*n)->next[0] = selectp;
(*n)->next[1] = starp;
(*n)->next[2] = fromp;
(*n)->next[3] = idp;
(*n)->next[4] = colp;
(*n)->csize = 5;
return 1;
}
return 0;
}
// sline 4
// SELECT '*' using pro_condition semi
int sline4(struct node **n)
{
struct node *selectp, *starp, *usingp, *pro_conditionp, *colp;
if(t_token("select",&selectp) && t_token("*", &starp) && using(&usingp) && pro_condition(&pro_conditionp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "sline4";
(*n)->next[0] = selectp;
(*n)->next[1] = starp;
(*n)->next[2] = usingp;
(*n)->next[3] = pro_conditionp;
(*n)->next[4] = colp;
(*n)->csize = 5;
return 1;
}
return 0;
}
// 10 line functions for representing productions emanating from line
// line: DELETE FROM IDENTIFIER semi
int line1(struct node **n)
{
struct node *deletep,*fromp,*idp,*colp;
if(t_token("delete",&deletep) && t_token("from",&fromp) && id(&idp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line1";
(*n)->next[0] = deletep;
(*n)->next[1] = fromp;
(*n)->next[2] = idp;
(*n)->next[3] = colp;
(*n)->csize = 4;
return 1;
}
return 0;
}
// line: DELETE FROM identifier WHERE
int line2(struct node **n)
{
struct node *deletep,*idp, *fromp, *wherep, *conditionp,*colp;
if(t_token("delete",&deletep)&& t_token("from", &fromp) && id(&idp) && t_token("where", &wherep) && condition(&conditionp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line2";
(*n)->next[0] = deletep;
(*n)->next[1] = fromp;
(*n)->next[2] = idp;
(*n)->next[3] = wherep;
(*n)->next[4] = conditionp;
(*n)->next[5] = colp;
(*n)->csize = 6;
return 1;
}
return 0;
}
// line: DROP TABLE IDENTIFIER semi
int line3(struct node **n)
{
struct node *dropp,*tablep,*idp,*colp;
if(t_token("drop",&dropp) && t_token("table",&tablep) && id(&idp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line3";
(*n)->next[0] = dropp;
(*n)->next[1] = tablep;
(*n)->next[2] = idp;
(*n)->next[3] = colp;
(*n)->csize = 4;
return 1;
}
return 0;
}
// line: ALTER TABLE IDENTIFIER DROP COLUMN items semi
int line4(struct node **n)
{
struct node *alterp,*dropp,*tablep,*columnp,*itemp,*idp,*colp;
if(t_token("alter" , &alterp)&& t_token("table", &tablep)&& id(&idp)&&t_token("drop",&dropp) && t_token("column" , &columnp) && items(&itemp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line4";
(*n)->next[0] = alterp;
(*n)->next[1] = tablep;
(*n)->next[2] = idp;
(*n)->next[3] = dropp;
(*n)->next[4] = columnp;
(*n)->next[5] = itemp;
(*n)->next[6] = colp;
(*n)->csize = 7;
return 1;
}
return 0;
}
// line: ALTER TABLE IDENTIFIER ADD IDENTIFIER IDENTIFIER semi
int line5(struct node **n)
{
struct node *alterp,*tablep, *addp , *id1p, *id2p, *id3p, *colp;
if(t_token("alter" , &alterp)&& t_token("table", &tablep)&& id(&id1p) && t_token("add", &addp) && id(&id2p)&& id(&id3p)&& t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line5";
(*n)->next[0] = alterp;
(*n)->next[1] = tablep;
(*n)->next[2] = id1p;
(*n)->next[3] = addp;
(*n)->next[4] = id2p;
(*n)->next[5] = id3p;
(*n)->next[6] = colp;
(*n)->csize = 7;
return 1;
}
return 0;
}
// line: INSERT INTO IDENTIFIER VALUES leftbr alpha_items rightbr semi
int line6(struct node **n)
{
struct node *insertp, *intop, *valuesp, *leftbrp, *alpha_itemsp, *rightbrp, *colp , *idp;
if(t_token("insert", &insertp) && t_token("into", &intop) && id(&idp)&& t_token("values", &valuesp) && t_token("(", &leftbrp) && alpha_items(&alpha_itemsp) && t_token(")", &rightbrp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line5";
(*n)->next[0] = insertp;
(*n)->next[1] = intop;
(*n)->next[2] = idp;
(*n)->next[3] = valuesp;
(*n)->next[4] = leftbrp;
(*n)->next[5] = alpha_itemsp;
(*n)->next[6] = rightbrp;
(*n)->next[7] = colp;
(*n)->csize = 8;
return 1;
}
return 0;
}
// line: INSERT INTO IDENTIFIER leftbr items rightbr VALUES leftbr alpha_items rightbr semi
int line7(struct node **n)
{
struct node *insertp, *intop, *idp, *itemsp, *valuesp, *leftbr1p, *rightbr1p, *alpha_itemsp, *leftbr2p, *rightbr2p, *colp;
if(t_token("insert", &insertp) && t_token("into", &intop) && id(&idp)&& t_token("(",&leftbr1p) && items(&itemsp) && t_token(")", &rightbr1p) && t_token("values", &valuesp) && t_token("(", &leftbr2p) && alpha_items(&alpha_itemsp) && t_token(")", &rightbr2p) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line7";
(*n)->next[0] = insertp;
(*n)->next[1] = intop;
(*n)->next[2] = idp;
(*n)->next[3] = leftbr1p;
(*n)->next[4] = itemsp;
(*n)->next[5] = rightbr1p;
(*n)->next[6] = valuesp;
(*n)->next[7] = leftbr2p;
(*n)->next[8] = alpha_itemsp;
(*n)->next[9] = rightbr2p;
(*n)->next[10] = colp;
(*n)->csize = 11;
return 1;
}
return 0;
}
// line: CREATE TABLE IDENTIFIER leftbr hyper_items rightbr semi
int line8(struct node **n)
{
struct node *createp, *tablep,*idp, *leftbrp, *hyper_itemsp, *rightbrp, *colp;
if(t_token("create", &createp) && t_token("table", &tablep) && id(&idp)&& t_token("(",&leftbrp) && hyper_items(&hyper_itemsp) && t_token(")", &rightbrp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line8";
(*n)->next[0] = createp;
(*n)->next[1] = tablep;
(*n)->next[2] = idp;
(*n)->next[3] = leftbrp;
(*n)->next[4] = hyper_itemsp;
(*n)->next[5] = rightbrp;
(*n)->next[6] = colp;
(*n)->csize = 7;
return 1;
}
return 0;
}
// line: UPDATE IDENTIFIER SET up_cond semi
int line9(struct node **n)
{
struct node *updatep, *idp, *setp, *up_condp, *colp;
if(t_token("update", &updatep) && id(&idp)&& t_token("set",&setp) && up_cond(&up_condp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line9";
(*n)->next[0] = updatep;
(*n)->next[1] = idp;
(*n)->next[2] = setp;
(*n)->next[3] = up_condp;
(*n)->next[4] = colp;
(*n)->csize = 5;
return 1;
}
return 0;
}
// line: UPDATE IDENTIFIER SET up_cond WHERE pro_condition semi
int line10(struct node **n)
{
struct node *updatep, *idp, *setp, *up_condp, *wherep, *pro_condp, *colp;
if(t_token("update", &updatep) && id(&idp)&& t_token("set",&setp) && up_cond(&up_condp) && t_token("where", &wherep) && pro_condition(&pro_condp) && t_token(";",&colp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "line10";
(*n)->next[0] = updatep;
(*n)->next[1] = idp;
(*n)->next[2] = setp;
(*n)->next[3] = up_condp;
(*n)->next[4] = wherep;
(*n)->next[5] = pro_condp;
(*n)->next[6] = colp;
(*n)->csize = 7;
return 1;
}
return 0;
}
// productions for conditions
// pro_condition: nes_condition | condition ;
int pro_condition(struct node **n)
{
int pc_point = parse_point;
struct node *idp ,*comp, *leftbrp , *new_linep , *rightbrp , *conditionp;
if(id(&idp)&&com(&comp)&&t_token("(",&leftbrp) && new_line(&new_linep) && t_token(")" , &rightbrp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "pro_condition";
(*n)->next[0] = idp;
(*n)->next[1] = comp;
(*n)->next[2] = leftbrp;
(*n)->next[3] = new_linep;
(*n)->next[4] = rightbrp;
(*n)->csize = 5;
return 1;
}
parse_point = pc_point;
if(condition(&conditionp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "pro_condition";
(*n)->next[0] = conditionp;
(*n)->csize = 1;
return 1;
}
parse_point = pc_point;
return 0;
}
// up_cond: IDENTIFIER '=' IDENTIFIER new_up_cond | IDENTIFIER '=' NUMBER new_up_cond;
int up_cond(struct node **n)
{
struct node *id1p , *eqp , *id2p , *new_up_condp , *nump;
int up_point = parse_point;
if(id(&id1p)&&t_token("=",&eqp) && id(&id2p) && new_up_cond(&new_up_condp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "up_cond";
(*n)->next[0] = id1p;
(*n)->next[1] = eqp;
(*n)->next[2] = id2p;
(*n)->next[3] = new_up_condp;
(*n)->csize = 4;
return 1;
}
parse_point = up_point;
if(id(&id1p)&&t_token("=", &eqp) && num(&nump) && new_up_cond(&new_up_condp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "up_cond";
(*n)->next[0] = id1p;
(*n)->next[1] = eqp;
(*n)->next[2] = nump;
(*n)->next[3] = new_up_condp;
(*n)->csize = 4;
return 1;
}
parse_point = up_point;
return 0;
}
// new_up_cond: ',' IDENTIFIER '=' IDENTIFIER new_up_cond | ',' IDENTIFIER '=' NUMBER new_up_cond | ;
int new_up_cond(struct node **n)
{
int nup_point = parse_point;
struct node *commap , *id1p , *eqp , *id2p , *new_up_condp, *nump;
if(t_token(",", &commap)&& id(&id1p)&&t_token("=",eqp) && id(&id2p) && new_up_cond(&new_up_condp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_up_cond";
(*n)->next[0] = commap;
(*n)->next[1] = id1p;
(*n)->next[2] = eqp;
(*n)->next[3] = id2p;
(*n)->next[4] = new_up_condp;
(*n)->csize = 5;
return 1;
}
parse_point = nup_point;
if( t_token(",",&commap)&& id(&id1p)&&t_token("=",eqp) && num(&nump) && new_up_cond(&new_up_condp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_up_cond";
(*n)->next[0] = commap;
(*n)->next[1] = id1p;
(*n)->next[2] = eqp;
(*n)->next[3] = nump;
(*n)->next[4] = new_up_condp;
(*n)->csize = 5;
return 1;
}
// special epislon case
parse_point = nup_point;
struct node *idd;
idd = (struct node *)malloc(sizeof(struct node));
idd->name = "";
idd->csize = 0;
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_up_cond";
(*n)->next[0] = idd;
(*n)->csize = 1;
return 1;
}
// new_line: SELECT items using pro_condition| SELECT items FROM IDENTIFIER
// new_line: SELECT '*' FROM IDENTIFIER | SELECT '*' using pro_condition ;
// for nested queries
int new_line(struct node **n)
{
int nl_point = parse_point;
struct node *selectp , *itemsp, *pro_conditionp , *fromp , *idp , *usingp , *starp;
if(t_token("select" , &selectp) && items(&itemsp) && using(&usingp) && pro_condition(&pro_conditionp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_line";
(*n)->next[0] = selectp;
(*n)->next[1] = itemsp;
(*n)->next[2] = usingp;
(*n)->next[3] = pro_conditionp;
(*n)->csize = 4;
return 1;
}
parse_point = nl_point;
if(t_token("select",&selectp) && items(&itemsp) && t_token("from",&fromp) && id(&idp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_line";
(*n)->next[0] = selectp;
(*n)->next[1] = itemsp;
(*n)->next[2] = fromp;
(*n)->next[3] = idp;
(*n)->csize = 4;
return 1;
}
parse_point = nl_point;
if(t_token("select",&selectp) && t_token("*",&starp) && t_token("from",&fromp) && id(&idp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_line";
(*n)->next[0] = selectp;
(*n)->next[1] = starp;
(*n)->next[2] = fromp;
(*n)->next[3] = idp;
(*n)->csize = 4;
return 1;
}
parse_point = nl_point;
if(t_token("select",&selectp) && t_token("*" , &starp) && using(&usingp) && pro_condition(&pro_conditionp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_line";
(*n)->next[0] = selectp;
(*n)->next[1] = starp;
(*n)->next[2] = usingp;
(*n)->next[3] = pro_conditionp;
(*n)->csize = 4;
return 1;
}
parse_point = nl_point;
return 0;
}
// using: FROM nes2 WHERE;
int using(struct node **n)
{
struct node *from,*nes2p,*where;
if(t_token("from",&from) && nes2(&nes2p) && t_token("where",&where))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "using";
(*n)->next[0] = from;
(*n)->next[1] = nes2p;
(*n)->next[2] = where;
(*n)->csize = 3;
return 1;
}
return 0;
}
// condition: IDENTIFIER comparator IDENTIFIER new_condition | IDENTIFIER comparator NUMBER new_condition;
int condition(struct node **n)
{
struct node *idp,*comp,*new_conditionp,*nump;
int c_point = parse_point;
if(id(&idp) && com(&comp) && id(&idp) && new_condition(&new_conditionp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "condition";
(*n)->next[0] = idp;
(*n)->next[1] = comp;
(*n)->next[2] = idp;
(*n)->next[3] = new_conditionp;
(*n)->csize = 4;
return 1;
}
parse_point = c_point;
if(id(&idp) && com(&comp) && num(&nump) && new_condition(&new_conditionp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "condition";
(*n)->next[0] = idp;
(*n)->next[1] = comp;
(*n)->next[2] = nump;
(*n)->next[3] = new_conditionp;
(*n)->csize = 4;
return 1;
}
parse_point = c_point;
return 0;
}
// nes2: Identifier | (new_line) | ';'
int nes2(struct node **n)
{
struct node *idp , *leftbrp,*rightbrp,*new_linep;
int nc_point = parse_point;
if(id(&idp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "nes2";
(*n)->next[0] = idp;
(*n)->csize = 1;
return 1;
}
parse_point = nc_point;
if(t_token("(", &leftbrp) && new_line(&new_linep) && t_token(")", &rightbrp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "nes2";
(*n)->next[0] = leftbrp;
(*n)->next[1] = new_linep;
(*n)->next[2] = rightbrp;
(*n)->csize = 3;
return 1;
}
// epsilon case
parse_point = nc_point;
struct node *idd;
idd = (struct node *)malloc(sizeof(struct node));
idd->name = "";
idd->csize = 0;
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "nes2";
(*n)->next[0] = idd;
(*n)->csize = 1;
return 1;
}
// new_condition: ao IDENTIFIER comparator IDENTIFIER new_condition | ao IDENTIFIER comparator NUMBER new_condition | ;
int new_condition(struct node **n)
{
struct node *aop , *idp , *comp , *nump , *new_conditionp;
int nc_point = parse_point;
if(ao(&aop)&& id(&idp) && com(&comp) && id(&idp) && new_condition(&new_conditionp))
{
*n = (struct node *)malloc(sizeof(struct node));
(*n)->name = "new_condition";
(*n)->next[0] = aop;
(*n)->next[1] = idp;
(*n)->next[2] = comp;
(*n)->next[3] = idp;
(*n)->next[4] = new_conditionp;
(*n)->csize = 5;
return 1;
}
parse_point = nc_point;
if(ao(&aop)&& id(&idp) && com(&comp) && num(&nump) && new_condition(&new_conditionp))
{