This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.y
1827 lines (1618 loc) · 71.1 KB
/
Parser.y
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
%{
#include<bits/stdc++.h>
#include "SymbolTable.cpp"
#include "StringHandler.h"
using namespace std;
int yyparse(void);
int yylex(void);
extern FILE *yyin;
extern int numberOfLines;
extern int numberOfErrors;
FILE* logs;
FILE* errors;
SymbolTable symbolTable(30);
map<string, string> SymbolSet;
vector< pair<string,string> >temp_param_list;
vector< pair<string,string> >arg_param_list;
vector<SymbolInfo*>v;
vector< pair<string,string> >decld_var_carrier; //vector for adding the variables to the assembly CODES
vector< pair<string,string> >var_carrier;
vector< pair<string,string> >decld_f_var; //vector for the declared variables inside the function to push the variables to the STACK
string type_of_var, statement_solver, return_type_solver, running_f_name = "", scope_holder = "";
bool is_func = false;
int control_arg, scope_counter = 1, scope_counter_2 = 0;
/* ******************* */
/* Output */
/* Procedure */
/* ******************* */
string output_procedure ="\nPRINT_INT PROC\
\n\tPUSH AX\
\n\tPUSH BX\
\n\tPUSH CX\
\n\tPUSH DX\
\n\n\tOR AX, AX\
\n\tJGE END_IF1\
\n\tPUSH AX\
\n\tMOV DL,'-'\
\n\tMOV AH, 2\
\n\tINT 21H\
\n\tPOP AX\
\n\tNEG AX\
\n\nEND_IF1:\
\n\tXOR CX, CX\
\n\tMOV BX, 10D\
\n\nREPEAT1:\
\n\tXOR DX, DX\
\n\tDIV BX\
\n\tPUSH DX\
\n\tINC CX\
\n\n\tOR AX, AX\
\n\tJNE REPEAT1\
\n\n\tMOV AH, 2\
\n\nPRINT_LOOP:\
\n\tPOP DX\
\n\tOR DL, 30H\
\n\tINT 21H\
\n\tLOOP PRINT_LOOP\
\n\tMOV AH, 2\
\n\tMOV DL, 10\
\n\tINT 21H\
\n\n\tMOV DL, 13\
\n\tINT 21H\
\n\n\tPOP DX\
\n\tPOP CX\
\n\tPOP BX\
\n\tPOP AX\
\n\tRET\
\nPRINT_INT ENDP\n\n";
// error detection
void yyerror(const char *s){
numberOfErrors++;
fprintf(errors, "Line no %d: %s\n", numberOfLines, s);
}
void symbolSet(){
SymbolSet["comma"] = ",";
SymbolSet["semicolon"] = ";";
SymbolSet["left_third"] = "[";
SymbolSet["right_third"] = "]";
SymbolSet["newline"] = "\n";
SymbolSet["left_first"] = "(";
SymbolSet["right_first"] = ")";
SymbolSet["equal"] = "=";
SymbolSet["plus"] = "+";
SymbolSet["minus"] = "-";
SymbolSet["left_curl"] = "{";
SymbolSet["right_curl"] = "}";
SymbolSet["incop"] = "++";
SymbolSet["decop"] = "--";
}
// get it
string getFromSymbolSet(string name){
return SymbolSet.at(name);
}
%}
%union{
SymbolInfo* symbolInfoPointer;
}
%token FOR IF DO INT FLOAT VOID COMMA SEMICOLON
%token ELSE WHILE DOUBLE CHAR RETURN CONTINUE
%token PRINTLN ASSIGNOP LPAREN RPAREN
%token LCURL RCURL LTHIRD RTHIRD
%token<symbolInfoPointer>CONST_INT
%token<symbolInfoPointer>CONST_FLOAT
%token<symbolInfoPointer>CONST_CHAR
%token<symbolInfoPointer>ADDOP
%token<symbolInfoPointer>MULOP
%token<symbolInfoPointer>LOGICOP
%token<symbolInfoPointer>BITOP
%token<symbolInfoPointer>RELOP
%token<symbolInfoPointer>INCOP
%token<symbolInfoPointer>DECOP
%token<symbolInfoPointer>ID
%token<symbolInfoPointer>NOT
%type <symbolInfoPointer> expression logic_expression simple_expression rel_expression type_specifier term unary_expression variable factor statement expression_statement compound_statement declaration_list var_declaration statements func_declaration func_definition parameter_list unit program argument_list arguments
// This is the starting point of implementation of bison grammar
%nonassoc LOWER_PREC_THAN_ELSE
%nonassoc ELSE
%left RELOP LOGICOP
%left ADDOP
%left MULOP
%type <symbolInfoPointer>start
%%
start : program {
fprintf(logs, "Line %d: start : program\n\n\n",numberOfLines-1);
symbolTable.printAllTable(logs);
/* ******************* */
/* ICG Code */
/* ******************* */
if(numberOfErrors == 0){
string first, second, temp = "";
temp = ".MODEL SMALL\
\n\n.STACK 100H\
\n\n.DATA\n";
for(int i = 0;i<decld_var_carrier.size(); i++){
first = decld_var_carrier[i].first;
second = decld_var_carrier[i].second;
if(second == ""){
temp = temp + first + " DW ?\n";
}else{
temp = temp + first + " DW "+
second + " dup(?)\n";
}
}
$1->extraSymbolInfo.assm_code = temp + "\n.CODE" + output_procedure + $1->extraSymbolInfo.assm_code;
ofstream out, optOut;
out.open("code.asm");
out << $1->extraSymbolInfo.assm_code;
optOut.open("optimized_code.asm");
optOut << optimizer($1->extraSymbolInfo.assm_code);
}else{
cout << "Error occurred. Check error.txt file" << endl;
}
};
program : program unit {
fprintf(logs, "Line %d: program : program unit\n\n", numberOfLines);
$$ -> extraSymbolInfo.stringAdder(getFromSymbolSet("newline") + $2 -> extraSymbolInfo.stringConcatenator);
fprintf(logs,"%s\n\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* ICG Code */
/* ******************* */
$$->extraSymbolInfo.assm_code = $1->extraSymbolInfo.assm_code + $2->extraSymbolInfo.assm_code;
} | unit {
fprintf(logs, "Line %d: program : unit\n\n", numberOfLines);
$$ -> extraSymbolInfo.stringConcatenator = $1 -> extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
};
unit : var_declaration{
fprintf(logs, "Line %d: unit : var_declaration\n\n", numberOfLines);
$$ -> extraSymbolInfo.stringConcatenator = $1 -> extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* ICG Code */
/* ******************* */
$$->extraSymbolInfo.assm_code = $1->extraSymbolInfo.assm_code;
} | func_declaration{
fprintf(logs, "Line %d: unit : func_declaration\n\n", numberOfLines);
$$ -> extraSymbolInfo.stringConcatenator = $1-> extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
} | func_definition{
fprintf(logs, "Line %d: unit : func_definition\n\n", numberOfLines);
$$ -> extraSymbolInfo.stringConcatenator = $1-> extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* ICG Code */
/* ******************* */
$$->extraSymbolInfo.assm_code = $1->extraSymbolInfo.assm_code;
};
func_declaration : type_specifier ID LPAREN parameter_list RPAREN SEMICOLON{
/* ************************************************************************ */
/* We need to check some properties of function declaration in this step: */
/* 1. Check return type is same */
/* 2. Check number of parameter is same */
/* 3. Check parameter sequence is same */
/* 4. No void Parameters are declared */
/* ************************************************************************ */
fprintf(logs, "Line %d: func_declaration : type_specifier ID LPAREN parameter_list RPAREN SEMICOLON\n\n", numberOfLines);
SymbolInfo* temp = symbolTable.LookUp($2->getName());
// if it found in symbol table
if(temp != 0){
// Checking return type
if(temp->extraSymbolInfo.returnTypeOfFunction != $1->getType()){
numberOfErrors++;
fprintf(errors, "Error at line %d : Return Type Mismatch of function declaration\n\n", numberOfLines);
}
// Checking parameter
if(temp->extraSymbolInfo.functionParamList.size()!=temp_param_list.size()){
numberOfErrors++;
fprintf(errors, "Error at line %d: Unequal number of parameters\n\n", numberOfLines++);
temp_param_list.clear();
}
// Checking parameter sequence
else{
for(int i=0;i<temp_param_list.size();i++){
if(temp_param_list[i].second != temp->extraSymbolInfo.functionParamList[i].second){
numberOfErrors++;
fprintf(errors, "Argument Type Mismatch with previous function declaration \n\n", numberOfLines);
}
}
temp_param_list.clear();
}
}
// if not found in symbol table
else{
// variable to check void type
bool isVoid = false;
// checking no void parameter is declared
for(int i=0;i<temp_param_list.size();i++){
if(temp_param_list[i].second=="VOID"){
isVoid = true;
break;
}
}
SymbolInfo* temp = new SymbolInfo();
temp->extraSymbolInfo.typeOfID = "FUNCTION";
temp->extraSymbolInfo.returnTypeOfFunction = $1->getType();
temp->extraSymbolInfo.isFunction = true;
temp->extraSymbolInfo.isFunctionDeclared = true;
temp->setName($2->getName());
temp->setType($2->getType());
if(isVoid){
numberOfErrors++;
fprintf(errors, "Error at line %d: Parameter cannot be void \n\n", numberOfLines);
temp->extraSymbolInfo.isFunction = false;
}
for(int i=0;i<temp_param_list.size();i++){
temp->extraSymbolInfo.functionParamList.push_back(make_pair(temp_param_list[i].first, temp_param_list[i].second));
}
temp_param_list.clear();
symbolTable.InsertModified(temp);
}
$$ -> extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator + $2->getName()+getFromSymbolSet("left_first")+$4->extraSymbolInfo.stringConcatenator+getFromSymbolSet("right_first")+getFromSymbolSet("semicolon");
fprintf(logs, "%s\n\n\n", $$->extraSymbolInfo.stringConcatenator.c_str());
} | type_specifier ID LPAREN RPAREN SEMICOLON {
fprintf(logs, "Line %d: func_declaration : type_specifier ID LPAREN RPAREN SEMICOLON\n\n", numberOfLines);
SymbolInfo* temp = symbolTable.LookUp($2->getName());
if(temp != 0){
if(temp->extraSymbolInfo.returnTypeOfFunction != $1->getType()){
numberOfErrors++;
fprintf(errors, "Error at Line %d: Return Type Mismatch of function declaration \n\n", numberOfLines);
}
if(temp->extraSymbolInfo.functionParamList.size()!=0){
numberOfErrors++;
fprintf(errors, "Error at Line %d : Unequal number of parameters\n\n", numberOfLines);
temp_param_list.clear();
} }else{
SymbolInfo* temp = new SymbolInfo();
temp->extraSymbolInfo.typeOfID = "FUNCTION";
temp->extraSymbolInfo.returnTypeOfFunction = $1->getType();
temp->extraSymbolInfo.isFunction = true;
temp->extraSymbolInfo.isFunctionDeclared = true;
temp->setName($2->getName());
temp->setType($2->getType());
for(int i=0;i<temp_param_list.size();i++){
temp->extraSymbolInfo.functionParamList.push_back(make_pair(temp_param_list[i].first, temp_param_list[i].second));
}
temp_param_list.clear();
symbolTable.InsertModified(temp);
}
$$ -> extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator + $2->getName()+getFromSymbolSet("left_first")+getFromSymbolSet("right_first")+getFromSymbolSet("semicolon");
fprintf(logs, "%s\n\n\n", $$->extraSymbolInfo.stringConcatenator.c_str());
};
func_definition : type_specifier ID LPAREN parameter_list RPAREN{
scope_counter = scope_counter + 1;
fprintf(logs, "Line %d: func_definition : type_specifier ID LPAREN parameter_list RPAREN compound_statement\n\n", numberOfLines);
SymbolInfo *s = symbolTable.LookUp($2->getName());
SymbolInfo *temp = new SymbolInfo();
bool flag = true;
// if it doest not exixts in any scope then insert the ID into
if(s==0){
bool check = false;
for(int i=0;i<temp_param_list.size();i++){
if(temp_param_list[i].second == "VOID"){
check = true;
}
}
// make a new object to insert into Symbol Table
temp->extraSymbolInfo.typeOfID = "FUNCTION";
temp->extraSymbolInfo.returnTypeOfFunction = $1->getType();
temp->extraSymbolInfo.isFunction = true;
temp->extraSymbolInfo.isFunctionDefined = true;
temp->setName($2->getName());
temp->setType($2->getType());
if(check){
numberOfErrors++;
fprintf(errors, "Error at line %d : Parameter cannot be VOID\n\n", numberOfLines);
temp->extraSymbolInfo.isFunction=false;
}
for(int i=0;i<temp_param_list.size();i++){
temp->extraSymbolInfo.functionParamList.push_back(make_pair(temp_param_list[i].first, temp_param_list[i].second));
temp->extraSymbolInfo.modfd_param_list.push_back(temp_param_list[i].first+to_string(scope_counter));
// pushing to the modified paramater list of the pointer
}
/*if(return_type_solver!=$1->getType())
{
numberOfErrors++;
fprintf(errors,"Error at Line %d : return type error \n\n",numberOfLines);
return_type_solver="";
temp->extraSymbolInfo.isFunction=false;
}*/
symbolTable.InsertModified(temp);
//temp_param_list.clear();
}
// if it already exists in global scope
else{
// function already exists
if(s->extraSymbolInfo.isFunctionDefined){
numberOfErrors++;
fprintf(errors, "Error at line %d: Multiple definition of function\n\n", numberOfLines);
temp_param_list.clear();
}else if(s->extraSymbolInfo.isFunctionDeclared){
/* Three case to handle here
1. Return type check
2. Check number of parameters and
3. Check for sequence of parameters */
s->extraSymbolInfo.isFunctionDefined = true;
string actReturnType = $1->getType();
string declaredReturnType = s->extraSymbolInfo.returnTypeOfFunction;
int declaredParamSize = s->extraSymbolInfo.functionParamList.size();
int definedParamSize = temp_param_list.size();
// Case 1: Return type Check
if(actReturnType != declaredReturnType){
numberOfErrors++;
fprintf(errors, "Error at line %d: Return type mismatch\n\n", numberOfLines);
flag = false;
}
// Case 2: Check for size of paramter list
else if(definedParamSize != definedParamSize){
numberOfErrors++;
fprintf(errors, "Error at line %d: Unequal number of parameters\n\n", numberOfLines);
temp_param_list.clear();
flag = false;
}
// Case 3: Check for sequence of parameter list
else{
for(int i = 0;i<temp_param_list.size();i++){
if(temp_param_list[i].second != s->extraSymbolInfo.functionParamList[i].second){
numberOfErrors++;
fprintf(errors, "Error at line %d: Argument Type Mismathch with function declaration\n\n", numberOfLines);
flag=false;
break;
}
}
// temp_param_list.clear();
for(int i =0;i<temp_param_list.size();i++)
{
s->extraSymbolInfo.modfd_param_list.push_back(temp_param_list[i].first+to_string(scope_counter)); //pushing to the modified paramater list of the pointer
}
}
if(return_type_solver!=$1->getType())
{
numberOfErrors++;
fprintf(errors,"Error at Line %d : return type error \n\n",numberOfLines);
return_type_solver="";
flag=false;
}
}
}
// $$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator+$2->getName()+getFromSymbolSet("left_first")+$4->extraSymbolInfo.stringConcatenator+getFromSymbolSet("right_first")+$6->extraSymbolInfo.stringConcatenator;
//fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* ICG Code */
/* ******************* */
running_f_name = $2->getName(); //saving the name to be used during returning
decld_var_carrier.push_back(make_pair(running_f_name+"_return_val", "")); //saving the variable in the .DATA segment of asm file
}compound_statement{
fprintf(logs, "Line %d: func_definition : type_specifier ID LPAREN parameter_list RPAREN compound_statement\n\n", numberOfLines);
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator+$2->getName()+getFromSymbolSet("left_first")+$4->extraSymbolInfo.stringConcatenator+getFromSymbolSet("right_first")+$7->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* ICG Code */
/* ******************* */
if($2->getName() == "main"){
$$->extraSymbolInfo.assm_code += "MAIN PROC\
\n\tMOV AX, @DATA\
\n\tMOV DS, AX\n";
$$->extraSymbolInfo.assm_code += $7->extraSymbolInfo.assm_code;
$$->extraSymbolInfo.assm_code += "\nLABEL_RETURN_";
$$->extraSymbolInfo.assm_code += running_f_name;
$$->extraSymbolInfo.assm_code += ":\n+\n\tMOV AH, 4CH\
\n\tINT 21H\
\nEND MAIN";
}else{
string temp_code = $2->getName()+" PROC\
\n\tPUSH AX\
\n\tPUSH BX\
\n\tPUSH CX\
\n\tPUSH DX\n\n";
/*---we lookup the func_id to access the parameter list---*/
SymbolInfo* s = symbolTable.LookUp($2->getName());
string hold = "";
stack<string>s1;
stack<string>s2;
/*---we push the parameters of the function to the stack of assm_code---*/
for(int i=0;i<s->extraSymbolInfo.functionParamList.size();i++){
hold = s->extraSymbolInfo.functionParamList[i].first+to_string(scope_counter);
temp_code += "\tPUSH "+hold+"\n";
s1.push(hold);
}
temp_code += "\n";
scope_holder = "";
/*---we push the declared variables of the function scope inside the stack of assm_code---*/
for(int i=0;i<decld_f_var.size();i++){
hold = decld_f_var[i].first;
temp_code += "\tPUSH "+hold+"\n";
s2.push(hold);
}
decld_f_var.clear(); //clearing the list so that we would not get any weird variables
temp_code += "\n"+$7->extraSymbolInfo.assm_code+"LABEL_RETURN_"+running_f_name+":\n";
/*---we pop the parameters of the function from the stack of assm_code---*/
while (!s2.empty()){
temp_code += "\tPOP "+s2.top()+"\n";
s2.pop();
}
temp_code += "\n";
/*---we pop the declared variables of the function from the stack of assm_code---*/
while (!s1.empty()){
temp_code += "\tPOP "+s1.top()+"\n";
s1.pop();
}
/*finally we pop the registers from the stack---*/
temp_code += "\n\tPOP DX\
\n\tPOP CX\
\n\tPOP BX\
\n\tPOP AX\
\n\tret\n\n";
temp_code += $2->getName();
temp_code += " ENDP\n\n";
/** we set the scope counter to the adjusted value so that next time another f is defined, we get the correct result */
scope_counter = scope_counter_2;
$$->extraSymbolInfo.assm_code += temp_code;
}
} | type_specifier ID LPAREN RPAREN{
fprintf(logs, "Line %d: func_definition : type_specifier ID LPAREN RPAREN compound_statement\n\n", numberOfLines);
scope_counter++;
SymbolInfo *s = symbolTable.LookUp($2->getName());
if(s==0){
SymbolInfo* temp = new SymbolInfo();
temp->extraSymbolInfo.typeOfID = "FUNCTION";
temp->extraSymbolInfo.returnTypeOfFunction = $1->getType();
temp->extraSymbolInfo.isFunction = true;
temp->extraSymbolInfo.isFunctionDefined = true;
temp->setName($2->getName());
temp->setType($2->getType());
symbolTable.InsertModified(temp);
}else{
if(s->extraSymbolInfo.isFunctionDeclared){
string actReturnType = $1->getType();
string funcReturnType = s->extraSymbolInfo.returnTypeOfFunction;
if(actReturnType != funcReturnType){
numberOfErrors++;
fprintf(errors, "Error at line %d: Return type mismatch\n\n", numberOfLines);
s->extraSymbolInfo.isFunction = false;
}
}else if(s->extraSymbolInfo.isFunctionDefined){
numberOfErrors++;
fprintf(errors,"Error at Line %d :Multiple defination of function\n\n",numberOfLines);
temp_param_list.clear();
}
}
//$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator+$2->getName()+getFromSymbolSet("left_first")+getFromSymbolSet("right_first")+$5->extraSymbolInfo.stringConcatenator;
//fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* ICG Code */
/* ******************* */
running_f_name = $2->getName(); //saving the name to be used during returning
decld_var_carrier.push_back(make_pair(running_f_name+"_return_val", ""));
}compound_statement{
fprintf(logs,"Line %d: func_definition : type_specifier ID LPAREN RPAREN compound_statement\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator+$2->getName()+getFromSymbolSet("left_first")+getFromSymbolSet("right_first")+$6->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* ICG Code */
/*for the main function*/
/* ******************* */
if($2->getName() == "main"){
$$->extraSymbolInfo.assm_code += "MAIN PROC\
\n\tMOV AX, @DATA\
\n\tMOV DS ,AX\n";
$$->extraSymbolInfo.assm_code += $6->extraSymbolInfo.assm_code;
$$->extraSymbolInfo.assm_code += "\nLABEL_RETURN_";
$$->extraSymbolInfo.assm_code += running_f_name;
$$->extraSymbolInfo.assm_code += ":\n\n\tMOV AH, 4CH\
\n\tINT 21H\
\nEND MAIN";
}else{
string temp_code = $2->getName()+" PROC\n";
/*---pushing the register to the STACK---*/
temp_code += "\tPUSH AX\
\n\tPUSH BX\
\n\tPUSH CX\
\n\tPUSH DX\n\n";
string hold = "";
stack<string>s2;
/*---we push the declared variables of the function scope inside the stack of assm_code---*/
for(int i=0;i<decld_f_var.size();i++){
hold = decld_f_var[i].first;
temp_code += "\tPUSH "+hold+"\n";
s2.push(hold);
}
decld_f_var.clear(); //clearing the list so that we would not get any weird variables
temp_code += "\n"+$6->extraSymbolInfo.assm_code;
temp_code += "LABEL_RETURN_";
temp_code += running_f_name;
temp_code += ":\n";
/*---we pop the parameters of the function from the stack of assm_code---*/
while (!s2.empty()){
temp_code += "\tPOP "+s2.top()+"\n";
s2.pop();
}
temp_code += "\n";
/*finally we pop the registers from the stack---*/
temp_code += "\n\tPOP DX\
\n\tPOP CX\
\n\tPOP BX\
\n\tPOP AX\
\n\tret\n\n";
temp_code += $2->getName()+" ENDP\n\n";
$$->extraSymbolInfo.assm_code += temp_code;
/** we set the scope counter to the adjusted value so that next time another f is defined, we get the correct result */
scope_counter = scope_counter_2;
}
};
parameter_list : parameter_list COMMA type_specifier ID
{
fprintf(logs,"Line %d: parameter_list : parameter_list COMMA type_specifier ID\n\n",numberOfLines);
temp_param_list.push_back(make_pair($4->getName(),$3->getType()));
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator+getFromSymbolSet("comma")+$3->extraSymbolInfo.stringConcatenator+$4->getName();
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
}
| parameter_list COMMA type_specifier
{
fprintf(logs,"Line %d: parameter_list : parameter_list COMMA type_specifier\n\n",numberOfLines);
temp_param_list.push_back(make_pair("",$3->getType()));
$$->extraSymbolInfo.stringConcatenator = $1->getName()+getFromSymbolSet("comma")+$3->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
}
| type_specifier ID
{
fprintf(logs,"Line %d: parameter_list : type_specifier ID\n\n", numberOfLines);
temp_param_list.push_back(make_pair($2->getName(),$1->getType()));
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator.append($2->getName());
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
}
| type_specifier
{
fprintf(logs,"Line %d: parameter_list : type_specifier\n\n",numberOfLines);
temp_param_list.push_back(make_pair("",$1->getType()));
$$->extraSymbolInfo.stringConcatenator =$1->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
};
compound_statement : LCURL {
symbolTable.EnterScope(logs);
// fprintf(logs,"Line %d: Entering Scope compound_statement LCURL\n\n",numberOfLines);
scope_counter_2 = symbolTable.getCurrentScopeID();
scope_holder = to_string(scope_counter_2);
if(temp_param_list.size()!=0){
for(int i=0;i<temp_param_list.size();i++){
string name = temp_param_list[i].first;
string type = temp_param_list[i].second;
SymbolInfo *s = new SymbolInfo();
s->setName(name);
s->setType("ID");
s->extraSymbolInfo.typeOfVar = type;
bool check = symbolTable.InsertModified(s);
decld_var_carrier.push_back(make_pair(name+to_string(scope_counter),""));
if(check == 0){
numberOfErrors++;
fprintf(errors, "Error at line %d: Duplicate Parameter Name of function\n\n", numberOfLines);
}
}
}
temp_param_list.clear();
} statements RCURL {
fprintf(logs,"Line %d: compound_statement : LCURL statements RCURL\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = getFromSymbolSet("left_curl")+"\n"+$3->extraSymbolInfo.stringConcatenator+getFromSymbolSet("right_curl");
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
symbolTable.printAllTable(logs);
symbolTable.ExitScope(logs);
$$->extraSymbolInfo.assm_code = $3->extraSymbolInfo.assm_code;
} | LCURL {
symbolTable.EnterScope(logs);
// fprintf(logs,"Line %d: LCURL Entering Scope LCURL\n\n",numberOfLines);
scope_counter_2 = symbolTable.getCurrentScopeID();
for(int i=0;i<temp_param_list.size();i++){
string name = temp_param_list[i].first;
string type = temp_param_list[i].second;
SymbolInfo *s = new SymbolInfo();
s->setName(name);
s->setType("ID");
s->extraSymbolInfo.typeOfVar = type;
bool check = symbolTable.InsertModified(s);
decld_var_carrier.push_back(make_pair(name+to_string(scope_counter), ""));
symbolTable.printAllTable(logs);
decld_var_carrier.push_back(make_pair(name+to_string(scope_counter),""));
if(check == 0){
numberOfErrors++;
fprintf(errors, "Error at line %d : Duplicate Parameter Name of function\n\n", numberOfLines);
}
}
temp_param_list.clear();
} RCURL {
fprintf(logs,"Line %d: compound_statement : LCURL RCURL\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = getFromSymbolSet("left_curl")+"\n"+getFromSymbolSet("right_curl");
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
symbolTable.printAllTable(logs);
symbolTable.ExitScope(logs);
};
var_declaration : type_specifier declaration_list SEMICOLON {
fprintf(logs,"Line %d: var_declaration : type_specifier declaration_list SEMICOLON\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = stringAdder(3,$1->extraSymbolInfo.stringConcatenator.c_str(),$2->extraSymbolInfo.stringConcatenator.c_str(),getFromSymbolSet("semicolon").c_str());
string first, second;
for(int i = 0; i<var_carrier.size() ; i++){
first = var_carrier[i].first;
second = var_carrier[i].second;
decld_var_carrier.push_back(make_pair(first+to_string(symbolTable.getCurrentScopeID()),second)); //pushing bacl to vector for assm_code declaration
if(symbolTable.getCurrentScopeID()!=1){
decld_f_var.push_back(make_pair(first+to_string(symbolTable.getCurrentScopeID()),second)); //pushing to the vector to be used during function defination procedure
}
}
var_carrier.clear();
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
};
type_specifier : INT {
fprintf(logs, "Line %d: type_specifier : INT\n\n", numberOfLines);
SymbolInfo* s = new SymbolInfo("", "INT");
type_of_var = "INT";
$$ = s;
$$->extraSymbolInfo.stringConcatenator = "int ";
fprintf(logs, "%s\n\n", $$->extraSymbolInfo.stringConcatenator.c_str());
} | FLOAT {
fprintf(logs,"Line %d: type_specifier : FLOAT\n\n",numberOfLines);
SymbolInfo* s = new SymbolInfo("","FLOAT");
type_of_var = "FLOAT";
$$ = s;
$$->extraSymbolInfo.stringConcatenator = "float ";
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
} | VOID {
fprintf(logs,"Line %d: type_specifier : VOID\n\n",numberOfLines);
SymbolInfo* s = new SymbolInfo("","VOID");
type_of_var = "VOID";
$$ = s;
$$->extraSymbolInfo.stringConcatenator = "void ";
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
};
declaration_list : declaration_list COMMA ID {
if(type_of_var!="VOID"){
fprintf(logs,"Line %d: declaration_list : declaration_list COMMA ID\n\n",numberOfLines);
SymbolInfo* test = symbolTable.currentScopeLookUp($3->getName());
if(test!=0){
fprintf(errors,"Error at Line %d : Multiple Declaration of %s\n\n",numberOfLines,$3->getName().c_str());
numberOfErrors++;
} else {
SymbolInfo* obj = new SymbolInfo($3->getName(),$3->getType());
obj->extraSymbolInfo.typeOfID = "VARIABLE";
obj->extraSymbolInfo.typeOfVar = type_of_var;
symbolTable.InsertModified(obj);
}
$1->extraSymbolInfo.stringConcatenator.append(getFromSymbolSet("comma"));
$$->extraSymbolInfo.stringConcatenator.append($3->getName());
var_carrier.push_back(make_pair($3->getName(),""));
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
}
} | declaration_list COMMA ID LTHIRD CONST_INT RTHIRD {
if(type_of_var!="VOID") {
fprintf(logs,"Line %d: declaration_list : declaration_list COMMA ID LTHIRD CONST_INT RTHIRD\n\n",numberOfLines);
SymbolInfo* test = symbolTable.currentScopeLookUp($3->getName());
if(test!=0) {
fprintf(errors,"Error at Line %d : Multiple Declaration of %s\n\n",numberOfLines,$3->getName().c_str());
numberOfErrors++;
} else {
SymbolInfo* obj = new SymbolInfo($3->getName(),$3->getType());
obj->extraSymbolInfo.typeOfID = "ARRAY";
obj->extraSymbolInfo.typeOfVar = type_of_var;
obj->extraSymbolInfo.sizeOfArray = $5->getName();
symbolTable.InsertModified(obj);
}
string temp = $3->getName()+getFromSymbolSet("left_third")+$5->getName()+getFromSymbolSet("right_third");
$1->extraSymbolInfo.stringConcatenator.append(getFromSymbolSet("comma"));
$$->extraSymbolInfo.stringConcatenator.append(temp);
var_carrier.push_back(make_pair($3->getName(), $5->getName()));
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
}
} | ID {
fprintf(logs,"Line %d: declaration_list : ID\n\n",numberOfLines);
if(type_of_var!="VOID"){
SymbolInfo* temp = symbolTable.currentScopeLookUp($1->getName());
if(temp!=0) {
numberOfErrors++;
fprintf(errors,"Error at Line %d : Multiple declration of %s\n\n",numberOfLines,$1->getName().c_str());
} else{
SymbolInfo* obj = new SymbolInfo($1->getName(),$1->getType());
obj->extraSymbolInfo.typeOfID = "VARIABLE";
obj->extraSymbolInfo.typeOfVar = type_of_var;
symbolTable.InsertModified(obj);
}
} else{
numberOfErrors++;
fprintf(errors,"Error at Line %d : Variable declared void\n\n",numberOfLines);
}
$$->extraSymbolInfo.stringConcatenator = $1->getName();
var_carrier.push_back(make_pair($1->getName(), ""));
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
} | ID LTHIRD CONST_INT RTHIRD {
fprintf(logs,"Line %d: declaration_list : ID LTHIRD CONST_INT RTHIRD\n\n",numberOfLines);
//checking to see if array type is void or not
if(type_of_var!="VOID")
{
SymbolInfo* temp = symbolTable.currentScopeLookUp($1->getName());
if(temp!=0){
fprintf(errors,"Error at Line %d : Multiple declration of %s\n\n",numberOfLines,$1->getName().c_str());
numberOfErrors++;
} else{
SymbolInfo* obj = new SymbolInfo($1->getName(),$1->getType());
obj->extraSymbolInfo.typeOfID = "ARRAY";
obj->extraSymbolInfo.typeOfVar = type_of_var;
obj->extraSymbolInfo.sizeOfArray = $3->getName();
symbolTable.InsertModified(obj);
}
} else {
fprintf(errors,"Error at Line %d : Array %s declared as void\n\n", numberOfLines,$1->getName().c_str());
numberOfErrors++;
}
string temp = getFromSymbolSet("left_third")+$3->getName()+getFromSymbolSet("right_third");
$$->extraSymbolInfo.stringConcatenator = $1->getName();
$$->extraSymbolInfo.stringConcatenator.append(temp);
var_carrier.push_back(make_pair($1->getName(), $3->getName()));
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
};
statements : statement{
fprintf(logs,"Line %d: statements : statement\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator+"\n";
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
$$->extraSymbolInfo.assm_code = $1->extraSymbolInfo.assm_code;
} | statements statement {
fprintf(logs,"Line %d: statements : statements statement\n\n", numberOfLines);
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator+($2->extraSymbolInfo.stringConcatenator+"\n");
statement_solver = $$->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
$$->extraSymbolInfo.assm_code = $1->extraSymbolInfo.assm_code + $2->extraSymbolInfo.assm_code;
};
statement : var_declaration {
fprintf(logs,"Line %d: statement : var_declaration\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
} | expression_statement {
fprintf(logs,"Line %d: statement : expression_statement\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
$$->extraSymbolInfo.assm_code = $1->extraSymbolInfo.assm_code;
} | compound_statement {
fprintf(logs,"Line %d: statement : compound_statement\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = $1->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
$$->extraSymbolInfo.assm_code = $1->extraSymbolInfo.assm_code;
} | FOR LPAREN expression_statement expression_statement expression RPAREN statement {
fprintf(logs,"Line %d: statement : FOR LPAREN expression_statement expression_statement expression RPAREN statement\n\n",numberOfLines);
string temp = $3->extraSymbolInfo.stringAdder($4->extraSymbolInfo.stringAdder($5->extraSymbolInfo.stringConcatenator));
$$->extraSymbolInfo.stringConcatenator = "for"+getFromSymbolSet("left_first")+temp+getFromSymbolSet("right_first")+$7->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
//var type of expression_statements and expression
string a = $3->extraSymbolInfo.typeOfVar;
string b = $4->extraSymbolInfo.typeOfVar;
string c = $5->extraSymbolInfo.typeOfVar;
if((a=="VOID")||(b=="VOID")||(c=="VOID")){
numberOfErrors++;
fprintf(errors,"Error at Line %d : Expression can not be void\n\n",numberOfLines);
}else{
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
char *label1 = newLabel(), *label2 = newLabel();
string temp_code = $3->extraSymbolInfo.assm_code+string(label1)+":\n"+$4->extraSymbolInfo.assm_code+"\tMOV AX, "+$4->extraSymbolInfo.carr1+"\n"+"\tCMP AX, 0\n"+"\tJE "+string(label2)+"\n"+$7->extraSymbolInfo.assm_code+$5->extraSymbolInfo.assm_code+"\tJMP "+string(label1)+"\n"+string(label2)+":\n\n";
$$->extraSymbolInfo.assm_code = temp_code;
}
} | IF LPAREN expression RPAREN statement %prec LOWER_PREC_THAN_ELSE{
fprintf(logs,"Line %d: IF LPAREN expression RPAREN statement\n\n",numberOfLines);
string temp = $3->extraSymbolInfo.stringAdder(getFromSymbolSet("right_first"));
$$->extraSymbolInfo.stringConcatenator = "if"+getFromSymbolSet("left_first")+temp+$5->extraSymbolInfo.stringConcatenator;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
string a = $3->extraSymbolInfo.typeOfVar;
if(a=="VOID"){
numberOfErrors++;
fprintf(errors,"Error at Line %d : Expression can not be void\n\n",numberOfLines);
}
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
char *label1 = newLabel();
string temp_code = $3->extraSymbolInfo.assm_code+"\tMOV AX, "+$3->extraSymbolInfo.carr1+"\n"+"\tCMP AX, 0\n"+"\tJE "+string(label1)+"\n"+$5->extraSymbolInfo.assm_code+string(label1)+":\n\n";
$$->extraSymbolInfo.assm_code = temp_code;
} | IF LPAREN expression RPAREN statement ELSE statement {
fprintf(logs,"Line %d: IF LPAREN expression RPAREN statement ELSE statement\n\n",numberOfLines);
string temp = $3->extraSymbolInfo.stringAdder(getFromSymbolSet("right_first"));
string temp2 = $5->extraSymbolInfo.stringAdder("else"+$7->extraSymbolInfo.stringConcatenator);
$$->extraSymbolInfo.stringConcatenator = "if"+getFromSymbolSet("left_first")+temp+temp2;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
string a = $3->extraSymbolInfo.typeOfVar;
if(a=="VOID"){
numberOfErrors++;
fprintf(errors,"Error at Line %d : Expression can not be void\n\n",numberOfLines);
}else{
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
char *label1 = newLabel(), *label2 = newLabel();
string temp_code = $3->extraSymbolInfo.assm_code+"\tMOV AX, "+$3->extraSymbolInfo.carr1+"\n"+"\tCMP AX, 0\n"+"\tJE "+string(label1)+"\n"+$5->extraSymbolInfo.assm_code+"\tJMP "+string(label2)+"\n"+"\tJMP "+string(label2)+"\n"+string(label1)+":\n"+$7->extraSymbolInfo.assm_code+string(label2)+":\n\n";
$$->extraSymbolInfo.assm_code = temp_code;
}
} | WHILE LPAREN expression RPAREN statement {
fprintf(logs,"Line %d: WHILE LPAREN expression RPAREN statement\n\n",numberOfLines);
string temp = $3->extraSymbolInfo.stringAdder(getFromSymbolSet("right_first")+$5->extraSymbolInfo.stringConcatenator);
$$->extraSymbolInfo.stringConcatenator = "while"+getFromSymbolSet("left_first")+temp;
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
string a = $3->extraSymbolInfo.typeOfVar;
if(a=="VOID"){
numberOfErrors++;
fprintf(errors,"Error at Line %d : Expression can not be void\n\n",numberOfLines);
}else{
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
char *label1 = newLabel(), *label2 = newLabel();
string temp_code = string(label1)+":\n"+$3->extraSymbolInfo.assm_code+"\tMOV AX, "+$3->extraSymbolInfo.carr1+"\n"+"\tCMP AX, 0\n"+"\tJE "+string(label2)+"\n"+$5->extraSymbolInfo.assm_code+"\tJMP "+string(label1)+"\n"+string(label2)+":\n\n";
$$->extraSymbolInfo.assm_code = temp_code;
}
} | PRINTLN LPAREN ID RPAREN SEMICOLON {
fprintf(logs,"Line %d: statement : PRINTLN LPAREN ID RPAREN SEMICOLON\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = "println"+getFromSymbolSet("left_first")+$3->getName()+getFromSymbolSet("right_first")+getFromSymbolSet("semicolon");
fprintf(logs,"%s\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
/* ******************* */
/* */
/* ICG Code */
/* */
/* ******************* */
string temp_code = "\n\n\tMOV AX, "+$3->getName()+to_string(symbolTable.IDlookUpWithParam($3->getName()))+"\n\tCALL PRINT_INT\n\n";
$$->extraSymbolInfo.assm_code = temp_code;
} | RETURN expression SEMICOLON {
fprintf(logs,"Line %d: statement : RETURN expression SEMICOLON\n\n",numberOfLines);
$$->extraSymbolInfo.stringConcatenator = "return "+$2->extraSymbolInfo.stringAdder(getFromSymbolSet("semicolon"));
fprintf(logs,"%s\n\n\n",$$->extraSymbolInfo.stringConcatenator.c_str());
string a = $2->extraSymbolInfo.typeOfVar;
if(a=="VOID"){
numberOfErrors++;
fprintf(errors,"Error at Line %d : Expression can not be void\n\n",numberOfLines);