-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpression.c
More file actions
1348 lines (1232 loc) · 61.2 KB
/
Copy pathexpression.c
File metadata and controls
1348 lines (1232 loc) · 61.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
/**
* Projekt IFJ/IAL 2019 - Překladač imperativního jazyka IFJ19
*
* @file expression.c
* @brief Sémantická analýza výrazu / volání funkce
*
* @author Daniel Pátek (xpatek08)
* @author Daniel Čechák (xcecha06)
*/
#include "expression.h"
Token token; //Token taken from scanner
//Precedence table with order from operands and operators from enum in scanner.h
const char precedenceTable[PT_SIZE][PT_SIZE] = {
// * / // + - = != < <= > >= == ( ) STR INT DOUB ID NONE $
/* * */ { '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '_' , '>' },
/* / */ { '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '_' , '>' },
/* // */ { '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '_' , '>' },
/* + */ { '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '_' , '>' },
/* - */ { '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '_' , '>' },
/* = */ { '<' , '<' , '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '_' , '>' },
/* != */ { '<' , '<' , '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '<' , '>' },
/* < */ { '<' , '<' , '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '<' , '>' },
/* <= */ { '<' , '<' , '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '<' , '>' },
/* > */ { '<' , '<' , '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '<' , '>' },
/* >= */ { '<' , '<' , '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '<' , '>' },
/* == */ { '<' , '<' , '<' , '<' , '<' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '<' , '>' , '<' , '<' , '<' , '<' , '<' , '>' },
/* ( */ { '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '=' , '<' , '<' , '<' , '<' , '<' , '_' },
/* ) */ { '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '_' , '>' , '_' , '_' , '_' , '_' , '_' , '>' },
/* STR */ { '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '_' , '>' , '_' , '_' , '_' , '_' , '_' , '>' },
/* INT */ { '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '_' , '>' , '_' , '_' , '_' , '_' , '_' , '>' },
/* DOUB*/ { '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '_' , '>' , '_' , '_' , '_' , '_' , '_' , '>' },
/* ID */ { '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '>' , '_' , '>' , '_' , '_' , '_' , '_' , '_' , '>' },
/* NONE*/ { '_' , '_' , '_' , '_' , '_' , '_' , '>' , '>' , '>' , '>' , '>' , '>' , '_' , '>' , '_' , '_' , '_' , '_' , '_' , '>' },
/* $ */ { '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '<' , '_' , '<' , '<' , '<' , '<' , '<' , '$' },
};
//Main funcion
int expression(VarType* returnValue) {/*,int expectedValue*/
ERROR_CODE result;
retVal = 8;//is indicating error in if or while
exp_stackInit(&stack_expression);
result = expressionAnalysis();
exp_stackClear(&stack_expression);
*returnValue = retVal;
return result;
}
//Analysis of the expression
int expressionAnalysis() {
ERROR_CODE result;
char sign = '_';//indicating error in expression
while(true) {
sign = getSignFromTable();//finds sign in precedence table
if(sign == '='){//only time we can expected equal sign is when we are reducing pars
exp_stackPush(&stack_expression,tokentoExp_element(token,false));
result = reducePars(&stack_expression);
if (result != ERROR_CODE_OK) {
return result;
}
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
}
else if(sign == '<'){
token_type next = peekNextToken();//checking next token for unexpected failure
if (next == TOKEN_UNDEF) {
return ERROR_CODE_LEX;
}
if (token.t_type == TOKEN_ID && next == TOKEN_LEFTPAR) {// processing function
result = makeFunction();
if (result != ERROR_CODE_OK) return result;
return ERROR_CODE_OK;
}
//checking for two operators behind each other
if (token.t_type == TOKEN_ADDITION || token.t_type == TOKEN_SUBTRACTION ||
token.t_type == TOKEN_MULTIPLICATION || token.t_type == TOKEN_DIVISION ||
token.t_type == TOKEN_INTEGER_DIVISION || token.t_type == TOKEN_EQUAL ||
token.t_type == TOKEN_EQUAL_EQUAL || token.t_type == TOKEN_BIGGERTHAN ||
token.t_type == TOKEN_BIGGERTHAN_EQUAL || token.t_type == TOKEN_SMALLERTHAN ||
token.t_type == TOKEN_SMALLERTHAN_EQUAL || token.t_type == TOKEN_NEG_EQUAL) {
if (stack_expression.top_of_stack->value->type == TOKEN_ADDITION ||
stack_expression.top_of_stack->value->type == TOKEN_SUBTRACTION ||
stack_expression.top_of_stack->value->type == TOKEN_MULTIPLICATION ||
stack_expression.top_of_stack->value->type == TOKEN_DIVISION ||
stack_expression.top_of_stack->value->type == TOKEN_INTEGER_DIVISION ||
stack_expression.top_of_stack->value->type == TOKEN_EQUAL_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_BIGGERTHAN_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_BIGGERTHAN ||
stack_expression.top_of_stack->value->type == TOKEN_SMALLERTHAN_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_SMALLERTHAN ||
stack_expression.top_of_stack->value->type == TOKEN_NEG_EQUAL) {
fprintf(stderr, "Dva operatory za sebou ve vyrazu. \n");
return ERROR_CODE_SYN;
}
}
if (token.t_type == TOKEN_ID || token.t_type == TOKEN_INT || token.t_type == TOKEN_DOUBLE || token.t_type == TOKEN_STRING || token.t_type == TOKEN_LEFTPAR || token.t_type == TOKEN_NONE){
exp_stackPush(&stack_expression,tokentoExp_element(token,true));
}
else{
if (exp_stackEmpty(&stack_expression)) {
fprintf(stderr, "Operátor musí mít obě strany. %d\n", token.t_type);
return ERROR_CODE_SYN;
}
exp_stackPush(&stack_expression,tokentoExp_element(token,false));
}
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
firstTerm = stack_expression.top_of_stack;
}
else if(sign == '>') {
//checking if the exoression ends with operator
if (token.t_type == TOKEN_EOL || token.t_type == TOKEN_EOF || token.t_type == TOKEN_DOUBLEDOT) {
if (stack_expression.top_of_stack->value->type == TOKEN_ADDITION ||
stack_expression.top_of_stack->value->type == TOKEN_SUBTRACTION ||
stack_expression.top_of_stack->value->type == TOKEN_MULTIPLICATION ||
stack_expression.top_of_stack->value->type == TOKEN_DIVISION ||
stack_expression.top_of_stack->value->type == TOKEN_INTEGER_DIVISION ||
stack_expression.top_of_stack->value->type == TOKEN_EQUAL_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_BIGGERTHAN_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_BIGGERTHAN ||
stack_expression.top_of_stack->value->type == TOKEN_SMALLERTHAN_EQUAL ||
stack_expression.top_of_stack->value->type == TOKEN_SMALLERTHAN ||
stack_expression.top_of_stack->value->type == TOKEN_NEG_EQUAL) {
fprintf(stderr, "Vyraz konci operatorem.\n");
return ERROR_CODE_SYN;
}
}
//processing of the expression
result = useRule(&stack_expression);
if (result != ERROR_CODE_OK) {
return result;
}
}
else if(sign == '$') {//simulates end of the expression
return ERROR_CODE_OK;
}
else{
fprintf(stderr, "Chybny vyraz (kompatibilita lexemu z vyrazu). %d\n", token.t_type);
if (stack_expression.top_of_stack != NULL) {
if (stack_expression.top_of_stack->value->type == TOKEN_NONE || token.t_type == TOKEN_NONE) {
return ERROR_CODE_SEM_COMP;
}
}
return ERROR_CODE_SYN;
}
}
}
// Funcion looking for sign in precedence table
char getSignFromTable(){
int a;// first terminal on stack
int b;//input token
if (token.t_type == TOKEN_EOL || token.t_type == TOKEN_EOF || token.t_type == TOKEN_DOUBLEDOT) {
b = TOKEN_UNDEF;
}
else {
b = token.t_type;
}
a = get_stack_type(&stack_expression);
return precedenceTable[a][b];
}
//Funcion initializating new element
Exp_element *newElement(int type,bool handle){
Exp_element *new_element = malloc(sizeof(struct exp_element));
//initialization if new element
if(new_element != NULL){
if(type == TOKEN_INT){
new_element->e_data.integer = token.t_data.integer;
}
if(type == TOKEN_DOUBLE){
new_element->e_data.decimal = token.t_data.decimal;
}
if(type == TOKEN_STRING){
new_element->e_data.ID = token.t_data.ID;
}
if (type == TOKEN_ID) {
stringInit(&(new_element->e_data.ID));
stringAddChars(&(new_element->e_data.ID), token.t_data.ID.value);
}
new_element->type = type;
new_element->handle = handle;
new_element->terminal = true;
return new_element;
}
else return NULL;
}
//Funcion getting type of first terminal on stack
int get_stack_type(ptrStack *stack_expression){
if (stack_expression->top_of_stack != NULL){
if (((Exp_element*)stack_expression->top_of_stack->value)->terminal == true){
return ((Exp_element*)stack_expression->top_of_stack->value)->type;
}
if (stack_expression->top_of_stack->left != NULL){
if (((Exp_element*)stack_expression->top_of_stack->left->value)->terminal == true){
return ((Exp_element*)stack_expression->top_of_stack->left->value)->type;
}
if (stack_expression->top_of_stack->left->left != NULL){
if (((Exp_element*)stack_expression->top_of_stack->left->left->value)->terminal == true){
return ((Exp_element*)stack_expression->top_of_stack->left->left->value)->type;
}
}
}
}
return ERROR_CODE_OK;
}
// Funcion transforming tokent to element
Exp_element *tokentoExp_element(Token token,bool handle){
int type;
if (token.t_type == TOKEN_EOL || token.t_type == TOKEN_EOF || token.t_type == TOKEN_DOUBLEDOT) {
type = TOKEN_UNDEF;
}
type = token.t_type;
Exp_element *element_to_stack = newElement(type, handle);
return element_to_stack;
}
//Funcion solving the expression and generates instructions
ERROR_CODE useRule(ptrStack *stack_expression){
ERROR_CODE result;
//switch checking for type of the terminal and
switch(firstTerm->value->type) {
//analysis of operands
case TOKEN_INT :
case TOKEN_DOUBLE:
case TOKEN_ID:
case TOKEN_STRING:
case TOKEN_NONE:
((Exp_element*)stack_expression->top_of_stack->value)->terminal = false;
((Exp_element *)stack_expression->top_of_stack->value)->handle = false;
((Exp_element *)stack_expression->top_of_stack->left->value)->handle = false;
firstTerm = stack_expression->top_of_stack->left;
//integer value
if (stack_expression->top_of_stack->value->type == TOKEN_INT) {
string operandString;
stringInit(&operandString);
char number[15];
sprintf(number, "%d", stack_expression->top_of_stack->value->e_data.integer);
stringAddChars(&operandString, number);
operand operand = initOperand(operand, operandString.value, stack_expression->top_of_stack->value->type, LF, false, false);
retVal = typeinteger;
oneOperandInstr(&instrList, PUSHS, operand);
}
//double value
else if (stack_expression->top_of_stack->value->type == TOKEN_DOUBLE) {
string operandString;
stringInit(&operandString);
char number[25];
sprintf(number, "%a", stack_expression->top_of_stack->value->e_data.decimal);
stringAddChars(&operandString, number);
operand operand = initOperand(operand, operandString.value, stack_expression->top_of_stack->value->type, LF, false, false);
retVal = typedouble;
oneOperandInstr(&instrList, PUSHS, operand);
}
//string value
else if (stack_expression->top_of_stack->value->type == TOKEN_STRING) {
operand operand = initOperand(operand, stack_expression->top_of_stack->value->e_data.ID.value, stack_expression->top_of_stack->value->type, LF, false, false);
retVal = typestring;
oneOperandInstr(&instrList, PUSHS, operand);
}
//there has to be ID analysis
else if (stack_expression->top_of_stack->value->type == TOKEN_ID) {
result = makeIdInstr();
if (result != ERROR_CODE_OK) return result;
}
else if (stack_expression->top_of_stack->value->type == TOKEN_NONE) {
retVal = undefined;
addInstruction(&instrList, PUSHS, "nil@nil", NULL, NULL);
}
return ERROR_CODE_OK;
// prossesing of addition and concatenation
case TOKEN_ADDITION :
if(stack_expression->top_of_stack->value->type == TOKEN_STRING) {
result = checkOperands(TOKEN_STRING, stack_expression->top_of_stack->value, stack_expression->top_of_stack->left->left->value);
if (result != ERROR_CODE_OK) return result;
string operandString;
stringInit(&operandString);
operand operand1 = initOperand(operand1,operandString.value,TOKEN_ID,LF, true, false);
operand operand2 = initOperand(operand2,stack_expression->top_of_stack->value->e_data.ID.value, stack_expression->top_of_stack->value->type, LF, false, false);
operand operand3 = initOperand(operand3,stack_expression->top_of_stack->left->left->value->e_data.ID.value, stack_expression->top_of_stack->left->left->value->type, LF, false, false);
threeOperandInstr(&instrList, CONCAT, operand1, operand2, operand3);
oneOperandInstr(&instrList, PUSHS, operand1);
break;
}
result = checkOperands(TOKEN_INT, stack_expression->top_of_stack->value, stack_expression->top_of_stack->left->left->value);
if (result != ERROR_CODE_OK) return result;
noOperandInstr(&instrList, ADDS);
break;
// prossesing of multiplication
case TOKEN_MULTIPLICATION :
result = checkOperands(TOKEN_INT, stack_expression->top_of_stack->value, stack_expression->top_of_stack->left->left->value);
if (result != ERROR_CODE_OK) return result;
noOperandInstr(&instrList, MULS);
break;
// prossesing of substraction
case TOKEN_SUBTRACTION:
result = checkOperands(TOKEN_INT, stack_expression->top_of_stack->value, stack_expression->top_of_stack->left->left->value);
if (result != ERROR_CODE_OK) return result;
noOperandInstr(&instrList, SUBS);
break;
// prossesing of division
case TOKEN_DIVISION:
if (stack_expression != NULL) {
if (stack_expression->top_of_stack != NULL) {
if (stack_expression->top_of_stack->value->type == TOKEN_INT) {
if (stack_expression->top_of_stack->value->e_data.integer == 0) {
return ERROR_CODE_ZERO_DEV;
}
}
else if(stack_expression->top_of_stack->value->type == TOKEN_DOUBLE) {
if (stack_expression->top_of_stack->value->e_data.decimal == 0.0) {
return ERROR_CODE_ZERO_DEV;
}
}
}
}
result = checkOperands(TOKEN_INT, stack_expression->top_of_stack->value, stack_expression->top_of_stack->left->left->value);
if (result != ERROR_CODE_OK) return result;
noOperandInstr(&instrList, DIVS);
break;
// prossesing of integer division
case TOKEN_INTEGER_DIVISION:
if (stack_expression != NULL) {
if (stack_expression->top_of_stack != NULL) {
if (stack_expression->top_of_stack->value->type == TOKEN_INT) {
if (stack_expression->top_of_stack->value->e_data.integer == 0) {
return ERROR_CODE_ZERO_DEV;
}
}
else if(stack_expression->top_of_stack->value->type == TOKEN_DOUBLE) {
if (stack_expression->top_of_stack->value->e_data.decimal == 0.0) {
return ERROR_CODE_ZERO_DEV;
}
}
}
}
result = checkOperands(TOKEN_INT, stack_expression->top_of_stack->value, stack_expression->top_of_stack->left->left->value);
if (result != ERROR_CODE_OK) return result;
noOperandInstr(&instrList, DIVS);
noOperandInstr(&instrList, FLOAT2INTS);
break;
// prossesing of comparison
case TOKEN_EQUAL_EQUAL:
noOperandInstr(&instrList, EQS);
break;
// prossesing of negetion of comparison
case TOKEN_NEG_EQUAL:
noOperandInstr(&instrList, EQS);
noOperandInstr(&instrList, NOTS);
break;
//prossesing of smallerthan
case TOKEN_SMALLERTHAN:
noOperandInstr(&instrList, LTS);
break;
//prossesing of biggerthan
case TOKEN_BIGGERTHAN:
noOperandInstr(&instrList, GTS);
break;
//prossesing of smallerthan equal
case TOKEN_SMALLERTHAN_EQUAL:
noOperandInstr(&instrList, GTS);
noOperandInstr(&instrList, NOTS);
break;
//prossesing of biggerthan equal
case TOKEN_BIGGERTHAN_EQUAL:
noOperandInstr(&instrList, LTS);
noOperandInstr(&instrList, NOTS);
break;
//else error
default:
return ERROR_CODE_SEM_COMP;
}
// popping solved elements from stack
exp_stackPop(stack_expression);
exp_stackPop(stack_expression);
//setting first terminal
if (stack_expression->top_of_stack != NULL) {
firstTerm = stack_expression->top_of_stack->left;
}
return ERROR_CODE_OK;
}
//funcion for reducing pars
ERROR_CODE reducePars(ptrStack *stack_expression){
if(stack_expression != NULL){
Exp_element* quicksave = stack_expression->top_of_stack->left->value;
exp_stackPop(stack_expression);
exp_stackPop(stack_expression);
exp_stackPop(stack_expression);
exp_stackPush(stack_expression,quicksave);
if((stack_expression->top_of_stack->left->value)->terminal == true) {
firstTerm = stack_expression->top_of_stack->left;
(firstTerm->value)->handle = false;
}
else return ERROR_CODE_SYN;
}
else return ERROR_CODE_SYN;
return ERROR_CODE_OK;
}
//Function for evaluation of IDs
ERROR_CODE makeIdInstr() {
tBSTNodePtr helpergf = SYMSearch(&glSymtable,stack_expression.top_of_stack->value->e_data.ID);
tBSTNodePtr helperlf = SYMSearch(&lcSymtable,stack_expression.top_of_stack->value->e_data.ID);
//first I have to check, if the id is not a function ID
if (helpergf != NULL) {
if (helpergf->DataType == Function) {
fprintf(stderr, "Ve vyrazu pouzivate ID funkce. (\"%s\")\n", stack_expression.top_of_stack->value->e_data.ID.value);
return ERROR_CODE_SEM;
}
}
if(helperlf != NULL) {
switch (helperlf->Vartype) {
case typeinteger:;
operand operand1 = initOperand(operand1, helperlf->Key.value, TOKEN_ID, LF, false, false);
retVal = typeinteger;
oneOperandInstr(&instrList, PUSHS, operand1);
break;
case typedouble:
retVal = typedouble;
operand operand2 = initOperand(operand2, helperlf->Key.value, TOKEN_ID, LF, false, false);
oneOperandInstr(&instrList, PUSHS, operand2);
break;
case typestring:
retVal = typestring;
operand operand3 = initOperand(operand3, helperlf->Key.value, TOKEN_ID, LF, false, false);
oneOperandInstr(&instrList, PUSHS, operand3);
break;
case undefined:
retVal = undefined;
operand operand4 = initOperand(operand4, helperlf->Key.value, TOKEN_ID, LF, false, false);
oneOperandInstr(&instrList, PUSHS, operand4);
break;
default:
//not initialized vartype -> err
printf("%s", helperlf->Key.value);
return ERROR_CODE_INTERNAL;
}
}
else if (helpergf != NULL) {
switch (helpergf->Vartype) {
case typeinteger:;
operand operand1 = initOperand(operand1, helpergf->Key.value, TOKEN_ID, GF, false, false);
retVal = typeinteger;
oneOperandInstr(&instrList, PUSHS, operand1);
break;
case typedouble:
retVal = typedouble;
operand operand2 = initOperand(operand2, helpergf->Key.value, TOKEN_ID, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand2);
break;
case typestring:
retVal = typestring;
operand operand3 = initOperand(operand3, helpergf->Key.value, TOKEN_ID, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand3);
break;
case undefined:
retVal = undefined;
operand operand4 = initOperand(operand4, helpergf->Key.value, TOKEN_ID, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand4);
break;
default:
//not initialized vartype -> err
return ERROR_CODE_INTERNAL;
}
}
else {
//ID wasnt found in symtable
fprintf(stderr, "Promenna \"%s\" se nenasla v tabulce symbolu.\n", stack_expression.top_of_stack->value->e_data.ID.value);
return ERROR_CODE_SEM;
}
return ERROR_CODE_OK;
}
ERROR_CODE makeFunction() {
retVal = undefined;
//i know for sure that now I have token ID as function name in token and nexttoken is leftpar
//starting function
//have to check if its in symtable
//print function is standalone
if (token.t_type == TOKEN_ID && strcmp(token.t_data.ID.value, "print") == 0) {
return makePrintFunction();
}
if (token.t_type == TOKEN_ID && strcmp(token.t_data.ID.value, "len") == 0) {
return makeLenFunction();
}
if (token.t_type == TOKEN_ID && strcmp(token.t_data.ID.value, "ord") == 0) {
return makeOrdFunction();
}
if (token.t_type == TOKEN_ID && strcmp(token.t_data.ID.value, "chr") == 0) {
return makeChrFunction();
}
if (token.t_type == TOKEN_ID && strcmp(token.t_data.ID.value, "substr") == 0) {
return makeSubstrFunction();
}
tBSTNodePtr helper = SYMSearch(&glSymtable, token.t_data.ID);
tBSTNodePtr helperLC = SYMSearch(&lcSymtable, token.t_data.ID);
if (helperLC != NULL) {
if (helperLC->DataType == Variable) {
//there has been variable with the same name
fprintf(stderr, "Jiz jste definovali promennou s nazvem \"%s\" ve funkci \"%s\".\n", token.t_data.ID.value, functionName.value);
return ERROR_CODE_SEM;
}
}
if (helper == NULL) {
//now I know that this function doesnt exist yet
if (strlen(functionName.value) != 0) {
//im in funcion and funcion is nost defined => still calling this funcion
//adding it to symtable (but as not defined)
SYMInsert(&glSymtable, token.t_data.ID, true);
helper = SYMSearch(&glSymtable, token.t_data.ID);
helper->defined = false;
//create temporary frame
noOperandInstr(&instrList, CREATEFRAME);
//count params
int paramsCounter = 0;
//eat (
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type != TOKEN_LEFTPAR) {
return ERROR_CODE_SYN;
}
//eat term
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
//now I have to generate params
while (token.t_type != TOKEN_RIGHTPAR) {
string nextParam;
stringInit(&nextParam);
stringAddChar(&nextParam, '%');
char str[3];
sprintf(str, "%d", paramsCounter);
stringAddChars(&nextParam, str);
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
oneOperandInstr(&instrList, DEFVAR, operand1);
switch(token.t_type) {
case TOKEN_STRING:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
operand2 = initOperand(operand2, token.t_data.ID.value, TOKEN_STRING, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_INT:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
string intString;
stringInit(&intString);
char str[15];
sprintf(str, "%d", token.t_data.integer);
stringAddChars(&intString, str);
operand2 = initOperand(operand2, intString.value, TOKEN_INT, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_DOUBLE:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
string doubleString;
stringInit(&doubleString);
char str2[40];
sprintf(str2, "%a", token.t_data.decimal);
stringAddChars(&doubleString, str2);
operand2 = initOperand(operand2, doubleString.value, TOKEN_DOUBLE, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_NONE:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
operand2 = initOperand(operand2, "None", TOKEN_STRING, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_ID:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
tBSTNodePtr helper2 = SYMSearch(&glSymtable, token.t_data.ID);
tBSTNodePtr helper3 = SYMSearch(&lcSymtable, token.t_data.ID);
if (helper2 == NULL && helper3 == NULL) {
fprintf(stderr, "Promenna \"%s\" pouzita pri volani funkce \"%s\" neni definovana.\n", token.t_data.ID.value, helper->Key.value);
return ERROR_CODE_SEM;
}
else if (helper2 != NULL) {
if (helper2->DataType != Variable) {
fprintf(stderr, "Pri volani funkce \"%s\" pouzivate v parametrech ID funkce: %s\n", helper->Key.value, token.t_data.ID.value);
return ERROR_CODE_SEM;
}
}
if (helper3 != NULL) {
operand2 = initOperand(operand2, helper3->Key.value , TOKEN_ID, LF, false, false);
}
else {
operand2 = initOperand(operand2, helper2->Key.value , TOKEN_ID, GF, false, false);
}
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
default:
fprintf(stderr, "Chyba v syntaxi volani funkce \"%s\".\n", helper->Key.value);
return ERROR_CODE_SYN;
}
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type == TOKEN_COMMA) {
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type == TOKEN_RIGHTPAR) {
//error in calling of the funcion
fprintf(stderr, "Chyba v syntaxi volani funkce \"%s\".\n", helper->Key.value);
return ERROR_CODE_SYN;
}
}
else if (token.t_type == TOKEN_RIGHTPAR) {
paramsCounter++;
continue;
}
else {
//error in calling of the funcion
fprintf(stderr, "Chyba v syntaxi volani funkce \"%s\".\n", helper->Key.value);
return ERROR_CODE_SYN;
}
paramsCounter++;
}
helper->parametrs = paramsCounter;
operand1 = initOperand(operand1, helper->Key.value, TOKEN_ID, GF, false, true);
oneOperandInstr(&instrList, CALL, operand1);
noOperandInstr(&instrList, POPFRAME);
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
return ERROR_CODE_OK;
}
else if(helper == NULL && strlen(functionName.value) == 0) {
//now im in main body -> error
fprintf(stderr, "Funkce v hlavnim tele neexistuje (%s).\n", token.t_data.ID.value);
return ERROR_CODE_SEM;
}
}
else {
//now I know that this function already exists (maybe still not defined)
if (helper->DataType != Function) {
//there has been variable with the same name
fprintf(stderr, "Definovali jste promennou s nazvem \"%s\", ne funkci.\n", token.t_data.ID.value);
return ERROR_CODE_SEM;
}
else {
//funcion is defined so
//create temporary frame
noOperandInstr(&instrList, CREATEFRAME);
//count params
int paramsCounter = 0;
//eat (
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type != TOKEN_LEFTPAR) {
return ERROR_CODE_SYN;
}
//eat term
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
//now I have to generate params
while (token.t_type != TOKEN_RIGHTPAR) {
string nextParam;
stringInit(&nextParam);
stringAddChar(&nextParam, '%');
char str[3];
sprintf(str, "%d", paramsCounter);
stringAddChars(&nextParam, str);
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
oneOperandInstr(&instrList, DEFVAR, operand1);
switch(token.t_type) {
case TOKEN_STRING:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
operand2 = initOperand(operand2, token.t_data.ID.value, TOKEN_STRING, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_INT:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
string intString;
stringInit(&intString);
char str[15];
sprintf(str, "%d", token.t_data.integer);
stringAddChars(&intString, str);
operand2 = initOperand(operand2, intString.value, TOKEN_INT, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_DOUBLE:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
string doubleString;
stringInit(&doubleString);
char str2[40];
sprintf(str2, "%a", token.t_data.decimal);
stringAddChars(&doubleString, str2);
operand2 = initOperand(operand2, doubleString.value, TOKEN_DOUBLE, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_NONE:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
operand2 = initOperand(operand2, "None", TOKEN_STRING, TF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
case TOKEN_ID:
operand1 = initOperand(operand1, nextParam.value, TOKEN_ID, TF, false, false);
tBSTNodePtr helper2 = SYMSearch(&glSymtable, token.t_data.ID);
tBSTNodePtr helper3 = SYMSearch(&lcSymtable, token.t_data.ID);
if (helper2 == NULL && helper3 == NULL) {
fprintf(stderr, "Promenna \"%s\" pouzita pri volani funkce \"%s\" neni definovana.\n", token.t_data.ID.value, helper->Key.value);
return ERROR_CODE_SEM;
}
else if (helper2 != NULL) {
if (helper2->DataType != Variable) {
fprintf(stderr, "Pri volani funkce \"%s\" pouzivate v parametrech ID funkce: %s\n", helper->Key.value, token.t_data.ID.value);
return ERROR_CODE_SEM;
}
}
if (helper3 != NULL) {
operand2 = initOperand(operand2, helper3->Key.value , TOKEN_ID, LF, false, false);
}
else {
operand2 = initOperand(operand2, helper2->Key.value , TOKEN_ID, GF, false, false);
}
twoOperandInstr(&instrList, MOVE, operand1, operand2);
break;
default:
fprintf(stderr, "Chyba v syntaxi volani funkce \"%s\".\n", helper->Key.value);
return ERROR_CODE_SYN;
}
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type == TOKEN_COMMA) {
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type == TOKEN_RIGHTPAR) {
//error in calling of the funcion
fprintf(stderr, "Chyba v syntaxi volani funkce \"%s\".\n", helper->Key.value);
return ERROR_CODE_SYN;
}
}
else if (token.t_type == TOKEN_RIGHTPAR) {
paramsCounter++;
continue;
}
else {
//error in calling of the funcion
fprintf(stderr, "Chyba v syntaxi volani funkce \"%s\".\n", helper->Key.value);
return ERROR_CODE_SYN;
}
paramsCounter++;
}
//now check params number
if (helper->defined == true) {
if (paramsCounter != helper->parametrs) {
fprintf(stderr, "Chybny pocet parametru pri volani funkce \"%s\".\n", helper->Key.value);
return ERROR_CODE_SEM_FUNC;
}
}
else {
helper->parametrs = paramsCounter;
}
operand1 = initOperand(operand1, helper->Key.value, TOKEN_ID, GF, false, true);
oneOperandInstr(&instrList, CALL, operand1);
noOperandInstr(&instrList, POPFRAME);
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
return ERROR_CODE_OK;
}
}
return ERROR_CODE_INTERNAL;
}
//buildin function print
ERROR_CODE makePrintFunction() {
retVal = undefined;
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer; //now leftpar
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer; //first term
operand1 = initOperand(operand1, "tmp2", TOKEN_ID, GF, false, false);
operand2 = initOperand(operand2, "2", TOKEN_INT, GF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
operand1 = initOperand(operand1, "%endwhile", TOKEN_STRING, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand1);
ptrStack myStack;
exp_stackInit(&myStack);
exp_stackPop(&myStack);
//params
while (token.t_type != TOKEN_RIGHTPAR ) {
if (token.t_type == TOKEN_STRING || token.t_type == TOKEN_ID || token.t_type == TOKEN_INT || token.t_type == TOKEN_DOUBLE || token.t_type == TOKEN_NONE) {
exp_stackPush(&myStack, tokentoExp_element(token, false));
}
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type == TOKEN_COMMA) {
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if (token.t_type == TOKEN_RIGHTPAR) {
return ERROR_CODE_SYN;
}
}
else if (token.t_type == TOKEN_RIGHTPAR) continue;
else {
fprintf(stderr, "Spatna syntax volani funkce \"print\".\n");
return ERROR_CODE_SYN;
}
}
//have to print params in another order
while (exp_stackEmpty(&myStack) != 1) {
switch(myStack.top_of_stack->value->type) {
case TOKEN_STRING:
operand1 = initOperand(operand1, myStack.top_of_stack->value->e_data.ID.value, TOKEN_STRING, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand1);
break;
case TOKEN_INT:;
string operandString;
stringInit(&operandString);
char number[15];
sprintf(number, "%d", myStack.top_of_stack->value->e_data.integer);
stringAddChars(&operandString, number);
operand1 = initOperand(operand1, operandString.value, TOKEN_STRING, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand1);
break;
case TOKEN_DOUBLE:;
string operandString1;
stringInit(&operandString1);
char number1[25];
sprintf(number1, "%a", myStack.top_of_stack->value->e_data.decimal);
stringAddChars(&operandString1, number1);
operand1 = initOperand(operand1, operandString1.value, TOKEN_STRING, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand1);
break;
case TOKEN_NONE:
operand1 = initOperand(operand1, "None", TOKEN_STRING, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand1);
break;
case TOKEN_ID:;
tBSTNodePtr helper22 = SYMSearch(&lcSymtable, myStack.top_of_stack->value->e_data.ID);
tBSTNodePtr helper33 = SYMSearch(&glSymtable, myStack.top_of_stack->value->e_data.ID);
if (helper33 != NULL) {
if (helper33->DataType == Function) {
fprintf(stderr, "Pri volani funkce \"print\" jste pouzili ID funkce. (%s)\n", myStack.top_of_stack->value->e_data.ID.value);
return ERROR_CODE_SEM;
}
}
if (helper22 == NULL && helper33 == NULL) {
fprintf(stderr, "Pri volani funkce \"print\" jste pouzili nedeklarovanou promennou: \"%s\"\n", myStack.top_of_stack->value->e_data.ID.value);
return ERROR_CODE_SEM;
}
else if (helper22 != NULL) {
operand1 = initOperand(operand1, myStack.top_of_stack->value->e_data.ID.value, TOKEN_ID, LF, false, false);
oneOperandInstr(&instrList, PUSHS, operand1);
}
else if (helper33 != NULL) {
operand1 = initOperand(operand1, myStack.top_of_stack->value->e_data.ID.value, TOKEN_ID, GF, false, false);
oneOperandInstr(&instrList, PUSHS, operand1);
}
break;
default:
return ERROR_CODE_SEM_OTHER;
}
//delete member
exp_stackPop(&myStack);
}
exp_stackClear(&myStack);
operand1 = initOperand(operand1, "print", TOKEN_ID, GF, false, true);
oneOperandInstr(&instrList, CALL, operand1);
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
return ERROR_CODE_OK;
}
//buildin function Len
ERROR_CODE makeLenFunction() {
retVal = typeinteger;
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer; //leftpar
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer; //first and only term
noOperandInstr(&instrList, CREATEFRAME);
if (token.t_type == TOKEN_ID) {
tBSTNodePtr helper2 = SYMSearch(&glSymtable, token.t_data.ID);
tBSTNodePtr helper3 = SYMSearch(&lcSymtable, token.t_data.ID);
if (helper2 == NULL && helper3 == NULL) {
fprintf(stderr, "Promenna \"%s\" pouzita pri volani funkce \"Len\" neni definovana.\n", token.t_data.ID.value);
return ERROR_CODE_SEM;
}
else if (helper2 != NULL) {
if (helper2->DataType != Variable) {
fprintf(stderr, "Pri volani funkce \"Len\" pouzivate v parametrech ID funkce: %s\n", token.t_data.ID.value);
return ERROR_CODE_SEM;
}
}
if (helper3 != NULL) {
if (helper3->Vartype == undefined || helper3->Vartype == typestring) {
addInstruction(&instrList, DEFVAR, "TF@%1", NULL, NULL);
operand1 = initOperand(operand1, "%1", TOKEN_ID, TF, false, false);
operand2 = initOperand(operand2, helper3->Key.value , TOKEN_ID, LF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
}
else {
fprintf(stderr, "Pouzili jste nespravny typ parametru pri volani funkce \"Len\".\n (%s)", token.t_data.ID.value);
return ERROR_CODE_SEM_COMP;
}
}
else {
if (helper2->Vartype == undefined || helper2->Vartype == typestring) {
addInstruction(&instrList, DEFVAR, "TF@%1", NULL, NULL);
operand1 = initOperand(operand1, "%1", TOKEN_ID, TF, false, false);
operand2 = initOperand(operand2, helper2->Key.value , TOKEN_ID, GF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
}
else {
fprintf(stderr, "Pouzili jste nespravny typ parametru pri volani funkce \"Len\".\n (%s)", token.t_data.ID.value);
return ERROR_CODE_SEM_COMP;
}
}
}
else if (token.t_type == TOKEN_STRING) {
addInstruction(&instrList, DEFVAR, "TF@%1", NULL, NULL);
operand1 = initOperand(operand1, "%1", TOKEN_ID, TF, false, false);
operand2 = initOperand(operand2, token.t_data.ID.value , TOKEN_STRING, GF, false, false);
twoOperandInstr(&instrList, MOVE, operand1, operand2);
}
else {
fprintf(stderr, "Pouzili jste nespravny parametr pri volani funkce \"Len\".\n");
return ERROR_CODE_SEM_COMP;
}
addInstruction(&instrList, CALL, "$len", NULL, NULL);
noOperandInstr(&instrList, POPFRAME);
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
if(token.t_type != TOKEN_RIGHTPAR) {
return ERROR_CODE_SYN;
}
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer;
return ERROR_CODE_OK;
}
//buildin function Ord
ERROR_CODE makeOrdFunction() {
retVal = typeinteger;
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer; //leftpar
if (((token = getNextToken(&line_flag, &s)).t_type) == TOKEN_UNDEF) return token.t_data.integer; //first and only term
noOperandInstr(&instrList, CREATEFRAME);
if (token.t_type == TOKEN_ID) {
tBSTNodePtr helper2 = SYMSearch(&glSymtable, token.t_data.ID);
tBSTNodePtr helper3 = SYMSearch(&lcSymtable, token.t_data.ID);
if (helper2 == NULL && helper3 == NULL) {
fprintf(stderr, "Promenna \"%s\" pouzita pri volani funkce \"Ord\" neni definovana.\n", token.t_data.ID.value);
return ERROR_CODE_SEM;
}