-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.c
867 lines (833 loc) · 20.6 KB
/
parser.c
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
/**
* IFJ Project 2020: Team 008, variant II
*
* @file parser.c
*
* @brief
*
*
* @author Martin Kneslík <xknesl02@stud.fit.vutbr.cz>
* @author Adriana Jurkechová <xjurke02@stud.fit.vutbr.cz>
* @author Karel Norek <xnorek01@stud.fit.vutbr.cz>
* @author Petr Salaba <xsalab00@stud.fit.vutbr.cz>
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "parser.h"
#include "expression.h"
#include "generator.h"
/**
* @brief initializes parser structure
*
* @return initialized structure
*/
Parser initParser()
{
Parser parser = malloc(sizeof(struct parser));
strInit(&parser->id);
strInit(&parser->typesLeft);
strInit(&parser->typesRight);
parser->tokenProcessed = true;
parser->funcInExpr = false;
parser->exprType = tNONE;
parser->exprIsBool = false;
parser->exprBoolAllowed = false;
parser->idType = tNONE;
parser->exprType = tNONE;
symtableInit(&parser->sGlobal);
symStackInit(&parser->sLocal);
addBuiltinFunc("print", "4", "", parser);
addBuiltinFunc("inputs", "", "20", parser);
addBuiltinFunc("inputi", "", "00", parser);
addBuiltinFunc("inputf", "", "10", parser);
addBuiltinFunc("int2float", "0", "1", parser);
addBuiltinFunc("float2int", "1", "0", parser);
addBuiltinFunc("len", "2", "0", parser);
addBuiltinFunc("substr", "200", "20", parser);
addBuiltinFunc("ord", "20", "00", parser);
addBuiltinFunc("chr", "0", "20", parser);
return parser;
}
/**
* @brief Clears parser structure
*
* @param parser parser structure
*/
void deleteParser(Parser parser)
{
strFree(&parser->id);
strFree(&parser->typesLeft);
strFree(&parser->typesRight);
symtableClearAll(&parser->sGlobal);
symStackDispose(&parser->sLocal);
free(parser);
}
/**
* @brief Main function of Parser
*
* @return Error code of parser
*/
int parse()
{
Parser parser = initParser();
generate_code(prog_init);
parser->returnCode = package(parser);
if (parser->returnCode == ERROR_CODE_OK)
{
symReadGlobal("main");
if (parser->currentFunc->argumentTypes.length != 0 || parser->currentFunc->returnTypes.length != 0)
{
parser->returnCode = ERROR_SEM_PARAM;
}
for (int i = 0; i < MAX_SYMSIZE; i++)
{
tSymtableItem *item = parser->sGlobal[i];
while (item)
{
if (!item->data->defined)
{
parser->returnCode = ERROR_SEM;
break;
}
item = item->ptrnext;
}
}
}
int returnCode = parser->returnCode;
deleteParser(parser);
return returnCode;
}
/**
* @brief <package> rule
*
* @return Error code of rule
*/
int package(Parser parser)
{
getToken();
while (isType(TOKEN_EOL))
getToken();
parser->tokenProcessed = false;
// <package> -> PACKAGE ID EOL <prog>
getKeyword(KW_PACKAGE);
getType(TOKEN_IDENTIFIER);
// only identifier "main" can follow after keyword package
if (strCmpConstStr(parser->token.attribute.string, "main"))
return ERROR_SYN;
getType(TOKEN_EOL);
getRule(prog);
generate_code(prog_end);
return ERROR_CODE_OK;
}
/**
* @brief <prog> rule
*
* @return Error code of rule
*/
int prog(Parser parser)
{
getToken();
// <prog> -> FUNC ID ( <params> ) <ret> { EOL <body> } EOL <prog>
if (isKeyword(KW_FUNC))
{
symStackPush(&parser->sLocal);
getType(TOKEN_IDENTIFIER);
symInsertGlobal(parser->token.attribute.string->str);
getType(TOKEN_LBRACKET);
getRule(params);
getType(TOKEN_RBRACKET);
getRule(ret);
parser->currentFunc->typesSet = true;
generate_code(func);
getType(TOKEN_LCURLYBRACKET);
getType(TOKEN_EOL);
getRule(body);
getType(TOKEN_RCURLYBRACKET);
getType(TOKEN_EOL);
if (parser->missingReturn)
return ERROR_SEM_PARAM;
symStackPop(&parser->sLocal);
generate_code(func_end);
getRule(prog);
}
//<prog> -> EOF
else if (isType(TOKEN_EOF))
{
}
else if (isType(TOKEN_EOL))
{
getRule(prog);
}
returnRule();
}
/**
* @brief <params> rule
*
* @return Error code of rule
*/
int params(Parser parser)
{
getToken();
// <params> -> ID <type> <params_n>
if (isType(TOKEN_IDENTIFIER))
{
strCopyString(&parser->id, parser->token.attribute.string);
symInsertLocal(parser->id.str);
parser->typeCounter = 0;
getRule(type);
generate_code(func_param);
getRule(params_n);
if (parser->typeCounter != parser->currentFunc->argumentTypes.length)
return ERROR_SEM_PARAM;
}
// <params> -> ε
else if (isType(TOKEN_RBRACKET))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <type> rule
*
* @return Error code of rule
*/
int type(Parser parser)
{
getToken();
if (isKeyword(KW_INT) || isKeyword(KW_FLOAT64) || isKeyword(KW_STRING))
{
parser->currentID->type = keywordToType(parser->token.attribute.keyword);
addType(typeToChar(parser->currentID->type), &parser->currentFunc->argumentTypes, parser->currentFunc, parser);
checkReturn();
}
returnRule();
}
/**
* @brief <params_n> rule
*
* @return Error code of rule
*/
int params_n(Parser parser)
{
getToken();
// <params_n> , ID <type> <params_n>
if (isType(TOKEN_COMMA))
{
getType(TOKEN_IDENTIFIER);
strCopyString(&parser->id, parser->token.attribute.string);
symInsertLocal(parser->id.str);
getRule(type);
generate_code(func_param);
getRule(params_n);
}
// <params_n> -> ε
else if (isType(TOKEN_RBRACKET))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <ret> rule
*
* @return Error code of rule
*/
int ret(Parser parser)
{
parser->missingReturn = true;
getToken();
// <ret> -> ( <ret_params> )
if (isType(TOKEN_LBRACKET))
{
getRule(ret_params);
getType(TOKEN_RBRACKET);
}
// <ret> -> ε
else if (isType(TOKEN_LCURLYBRACKET))
{
parser->missingReturn = false;
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <ret_params> rule
*
* @return Error code of rule
*/
int ret_params(Parser parser)
{
getToken();
//<ret_params> -> <type> <ret_params_n>
if (isKeyword(KW_INT) || isKeyword(KW_FLOAT64) || isKeyword(KW_STRING))
{
parser->typeCounter = 0;
addType(typeToChar(keywordToType(parser->token.attribute.keyword)), &parser->currentFunc->returnTypes, parser->currentFunc, parser);
checkReturn();
getRule(ret_params_n);
if (parser->typeCounter != parser->currentFunc->returnTypes.length)
return ERROR_SEM_PARAM;
}
//<ret_params>->ε
else if (isType(TOKEN_RBRACKET))
{
parser->missingReturn = false;
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <ret_params_n> rule
*
* @return Error code of rule
*/
int ret_params_n(Parser parser)
{
getToken();
//<ret_params_n>->, <type> <ret_params_n>
if (isType(TOKEN_COMMA))
{
getToken();
if (isKeyword(KW_INT) || isKeyword(KW_FLOAT64) || isKeyword(KW_STRING))
{
addType(typeToChar(keywordToType(parser->token.attribute.keyword)), &parser->currentFunc->returnTypes, parser->currentFunc, parser);
checkReturn();
}
getRule(ret_params_n);
}
//<ret_params_n>->ε
else if (isType(TOKEN_RBRACKET))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <body> rule
*
* @return Error code of rule
*/
int body(Parser parser)
{
strClear(&parser->typesLeft);
strClear(&parser->typesRight);
getToken();
// <body> -> FOR <for_definition> ; <expression> ; <for_assign> { EOL <body> } EOL <body>
if (isKeyword(KW_FOR))
{
symStackPush(&parser->sLocal);
generate_code(for_begin);
getRule(for_definition);
getType(TOKEN_SEMICOLON);
generate_code(for_condition);
parser->exprBoolAllowed = true;
getRule(expression);
parser->exprBoolAllowed = false;
getType(TOKEN_SEMICOLON);
generate_code(for_assign);
getRule(for_assign);
getType(TOKEN_LCURLYBRACKET);
getType(TOKEN_EOL);
symStackPush(&parser->sLocal);
generate_code(for);
getRule(body);
getType(TOKEN_RCURLYBRACKET);
getType(TOKEN_EOL);
symStackPop(&parser->sLocal);
symStackPop(&parser->sLocal);
generate_code(endfor);
getRule(body);
}
// <body> -> IF <expression> { EOL <body> } ELSE { EOL <body> } EOL <body>
else if (isKeyword(KW_IF))
{
parser->exprBoolAllowed = true;
getRule(expression);
parser->exprBoolAllowed = false;
getType(TOKEN_LCURLYBRACKET);
getType(TOKEN_EOL);
generate_code(if);
symStackPush(&parser->sLocal);
getRule(body);
symStackPop(&parser->sLocal);
getType(TOKEN_RCURLYBRACKET);
getKeyword(KW_ELSE);
getType(TOKEN_LCURLYBRACKET);
getType(TOKEN_EOL);
generate_code(else);
symStackPush(&parser->sLocal);
getRule(body);
symStackPop(&parser->sLocal);
getType(TOKEN_RCURLYBRACKET);
getType(TOKEN_EOL);
generate_code(endif);
getRule(body);
}
// <body> -> RETURN <ret_values> EOL <body>
else if (isKeyword(KW_RETURN))
{
parser->missingReturn = false;
parser->typeCounter = 0;
getRule(ret_values);
if (!compareTypes(parser->typesRight, parser->currentFunc->returnTypes))
return ERROR_SEM_PARAM;
getType(TOKEN_EOL);
generate_code(return);
getRule(body);
}
// <body> -> ID <body_n> EOL <body>
else if (isType(TOKEN_IDENTIFIER))
{
strCopyString(&parser->id, parser->token.attribute.string);
getRule(body_n);
getType(TOKEN_EOL);
getRule(body);
}
// skip empty lines
else if (isType(TOKEN_EOL))
{
getRule(body);
}
// <body> -> ε
else if (isType(TOKEN_RCURLYBRACKET))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <body_n> rule
*
* @return Error code of rule
*/
int body_n(Parser parser)
{
getToken();
//<body_n> -> <definition>
if (isType(TOKEN_VAR_DEF))
{
parser->tokenProcessed = false;
getRule(definition);
}
//<body_n> -> <assign>
else if (isType(TOKEN_COMMA) || isType(TOKEN_ASSIGN))
{
parser->tokenProcessed = false;
getRule(assign);
}
//<body_n>-> ( <arg> )
else if (isType(TOKEN_LBRACKET))
{
parser->tokenProcessed = false;
getRule(func);
generate_code(void_func_call);
}
returnRule();
}
/**
* @brief <id_n> rule
*
* @return Error code of rule
*/
int id_n(Parser parser)
{
getToken();
// <id_n> -> , ID <id_n>
if (isType(TOKEN_COMMA))
{
getType(TOKEN_IDENTIFIER);
strCopyString(&parser->id, parser->token.attribute.string);
if (strCmpConstStr(&parser->id, "_") != 0)
{
symReadLocal(parser->id.str);
parser->idType = parser->currentID->type;
}
else
{
parser->idType = tNONE;
}
generate_code(assign_push_id);
strAddChar(&parser->typesLeft, typeToChar(parser->idType));
getRule(id_n);
}
// <id_n> -> ε
else if (isType(TOKEN_ASSIGN))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <for_definition> rule
*
* @return Error code of rule
*/
int for_definition(Parser parser)
{
getToken();
// <for_definition> -> ID <definition>
if (isType(TOKEN_IDENTIFIER))
{
strCopyString(&parser->id, parser->token.attribute.string);
getRule(definition);
}
// <for_definition> -> ε
else if (isType(TOKEN_SEMICOLON))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <for_assign> rule
*
* @return Error code of rule
*/
int for_assign(Parser parser)
{
getToken();
// <for_assign> -> ID <assign>
if (isType(TOKEN_IDENTIFIER))
{
strCopyString(&parser->id, parser->token.attribute.string);
getRule(assign);
}
// <for_assign> -> ε
else if (isType(TOKEN_LCURLYBRACKET))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <value> rule
*
* @return Error code of rule
*/
int value(Parser parser)
{
// <value> -> ID <func>
getRule(expression);
if (parser->funcInExpr)
{
getType(TOKEN_IDENTIFIER);
strCopyString(&parser->id, parser->token.attribute.string);
getToken();
if (!isType(TOKEN_LBRACKET))
return ERROR_SEM;
parser->tokenProcessed = false;
getRule(func);
generate_code(func_call);
}
// <value> -> <expression> <expression_n>
else
{
strAddChar(&parser->typesRight, typeToChar(parser->exprType));
getRule(expression_n);
}
return ERROR_CODE_OK;
}
/**
* @brief <expression_n> rule
*
* @return Error code of rule
*/
int expression_n(Parser parser)
{
getToken();
// <expression_n> -> , <expression> <expression_n>
if (isType(TOKEN_COMMA))
{
getRule(expression);
strAddChar(&parser->typesRight, typeToChar(parser->exprType));
getRule(expression_n);
}
// <expression_n> -> ε
else if (isType(TOKEN_LCURLYBRACKET) || isType(TOKEN_EOL))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <definition> rule
*
* @return Error code of rule
*/
int definition(Parser parser)
{
// <definition> -> := <expression>
getType(TOKEN_VAR_DEF);
getRule(expression);
if (parser->funcInExpr)
return ERROR_SEM;
symInsertLocal(parser->id.str);
parser->currentID->type = parser->exprType;
generate_code(define_var);
return ERROR_CODE_OK;
}
/**
* @brief <assign> rule
*
* @return Error code of rule
*/
int assign(Parser parser)
{
if (strCmpConstStr(&parser->id, "_") != 0)
{
symReadLocal(parser->id.str);
parser->idType = parser->currentID->type;
}
else
{
parser->idType = tNONE;
}
generate_code(assign_push_id);
strAddChar(&parser->typesLeft, typeToChar(parser->idType));
// <assign> -> <id_n> = <value>
getRule(id_n);
getType(TOKEN_ASSIGN);
getRule(value);
if (!compareTypes(parser->typesLeft, parser->typesRight))
return ERROR_SEM_OTHER;
generate_code(assign);
checkReturn();
return ERROR_CODE_OK;
}
/**
* @brief <func> rule
*
* @return Error code of rule
*/
int func(Parser parser)
{
getToken();
// <func> -> ( <arg> )
if (isType(TOKEN_LBRACKET))
{
if (symtableReadStack(&parser->sLocal, parser->id.str) != NULL)
return ERROR_SEM;
parser->calledFunc = symtableInsert(&parser->sGlobal, parser->id.str);
symCheckNull(parser->calledFunc);
getRule(arg);
getType(TOKEN_RBRACKET);
if (!parser->calledFunc->typesSet && !parser->calledFunc->defined)
{
strCopyString(&parser->calledFunc->argumentTypes, &parser->typesRight);
strCopyString(&parser->calledFunc->returnTypes, &parser->typesLeft);
parser->calledFunc->typesSet = true;
}
if (!compareTypes(parser->calledFunc->argumentTypes, parser->typesRight))
return ERROR_SEM_PARAM;
strCopyString(&parser->typesRight, &parser->calledFunc->returnTypes);
}
returnRule();
}
/**
* @brief <arg> rule
*
* @return Error code of rule
*/
int arg(Parser parser)
{
getToken();
// <arg> -> <term> <term_n>
if (isType(TOKEN_IDENTIFIER) || isType(TOKEN_INT) || isType(TOKEN_FLOAT) || isType(TOKEN_STRING))
{
parser->tokenProcessed = false;
getRule(term);
generate_code(stack_push);
getRule(term_n);
}
// <arg> -> ε
else if (isType(TOKEN_RBRACKET))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <term> rule
*
* @return Error code of rule
*/
int term(Parser parser)
{
getToken();
// <term> -> ID
if (isType(TOKEN_IDENTIFIER))
{
if (!strCmpConstStr(parser->token.attribute.string, "_"))
return ERROR_SEM;
strCopyString(&parser->id, parser->token.attribute.string);
symReadLocal(parser->token.attribute.string->str);
strAddChar(&parser->typesRight, typeToChar(parser->currentID->type));
}
// <term> -> VALUE_INT
else if (isType(TOKEN_INT))
{
strAddChar(&parser->typesRight, typeToChar(tINT));
}
// <term> -> VALUE_FLOAT64
else if (isType(TOKEN_FLOAT))
{
strAddChar(&parser->typesRight, typeToChar(tFLOAT64));
}
// <term> -> VALUE_STRING
else if (isType(TOKEN_STRING))
{
strAddChar(&parser->typesRight, typeToChar(tSTRING));
}
returnRule();
}
/**
* @brief <term_n> rule
*
* @return Error code of rule
*/
int term_n(Parser parser)
{
getToken();
// <term_n> -> , <term> <term_n>
if (isType(TOKEN_COMMA))
{
getRule(term);
generate_code(stack_push);
getRule(term_n);
}
// <term_n> -> ε
else if (isType(TOKEN_RBRACKET))
{
parser->tokenProcessed = false;
}
returnRule();
}
/**
* @brief <ret_values> rule
*
* @return Error code of rule
*/
int ret_values(Parser parser)
{
getToken();
//<ret_values> -> ε
if (isType(TOKEN_EOL))
{
parser->tokenProcessed = false;
return ERROR_CODE_OK;
}
//<ret_values> -> <value>
else
{
parser->tokenProcessed = false;
getRule(value);
return ERROR_CODE_OK;
}
}
/**
* @brief Adds built-in function to global symtable
*
* @param key function name
* @param argumentTypes argument types in string form
* @param returnTypes return types in string form
* @param parser parser structure
* @return int
*/
int addBuiltinFunc(char *key, char *argumentTypes, char *returnTypes, Parser parser)
{
symInsertGlobal(key);
for (int i = 0; i < strlen(argumentTypes); i++)
strAddChar(&parser->currentFunc->argumentTypes, argumentTypes[i]);
for (int i = 0; i < strlen(returnTypes); i++)
strAddChar(&parser->currentFunc->returnTypes, returnTypes[i]);
}
/**
* @brief Converts keyword enum to datatype enum
*
* @param keyword keyword to convert
* @return DataType enum
*/
DataType keywordToType(Keyword keyword)
{
if (keyword == KW_INT)
return tINT;
else if (keyword == KW_FLOAT64)
return tFLOAT64;
else if (keyword == KW_STRING)
return tSTRING;
else
return tNONE;
}
/**
* @brief Converts datatype enum to type in char format
*
* @param type
* @return type as char
* 0 - int
* 1 - float64
* 2 - string
* 3 - none / underscore
* 4 - multiple
*/
char typeToChar(DataType type)
{
if (type == tINT)
return '0';
else if (type == tFLOAT64)
return '1';
else if (type == tSTRING)
return '2';
else if (type == tNONE)
return '3';
else if (type == tMULTIPLE)
return '4';
}
/**
* @brief Compares two data types in string format
*
* @param typesLeft data type in string format
* @param typesRight data type in string format
* @return true if types match
* @return false if types dont match
*/
bool compareTypes(string typesLeft, string typesRight)
{
if (typesLeft.str[0] == typeToChar(tMULTIPLE))
return true;
if (typesLeft.length != typesRight.length)
return false;
for (int i = 0; i < typesLeft.length; i++)
{
if (typesLeft.str[i] == typeToChar(tNONE))
continue;
else if (typesLeft.str[i] != typesRight.str[i])
return false;
}
return true;
}
/**
* @brief Adds type in char format to list of types in string format
*
* @param type type in char format
* @param typesList list of types in string format
* @param data struct of symtable data that contains list of types
* @param parser parser structure
*/
void addType(char type, string *typesList, tSymtableData data, Parser parser)
{
if (data->typesSet)
{
if (parser->typeCounter >= typesList->length)
parser->returnCode = ERROR_SEM_PARAM;
if (typesList->str[parser->typeCounter] != type)
parser->returnCode = ERROR_SEM_PARAM;
}
else
{
strAddChar(typesList, type);
parser->returnCode = ERROR_CODE_OK;
}
parser->typeCounter++;
}