-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.c
3798 lines (3044 loc) · 105 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
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
/**
* Project: IFJ21 imperative language compiler
*
* Brief: Syntax and Semantic Analysis for IFJ21 compiler - parser part
*
* Author: David Chocholaty <xchoch09>
*
*/
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "parser.h"
#include "scanner.h"
#include "error.h"
#include "psa.h"
#include "symtable.h"
#include "sym_linked_list.h"
#include "code_generator.h"
#include "paramstack.h"
#include "ids_list.h"
#define PROLOG "ifj21"
#define IS_NIL 1
#define NOT_NIL 0
#define DEF 2
#define VALIDATE_TOKEN(token) \
if (!valid_token(token)) \
{ \
return false; \
}
#define TEST_EOF(token) \
if(token == NULL && err == E_NO_ERR) \
{ \
return false; \
} \
#define PUSH_PARAMS(data) \
if (!push_params_code_gen(data)) \
{ \
return false; \
} \
/*
NON-TERMINALS
<prog>
<main_b>
<stats>
<id_func>
<params>
<n_params>
<n_ids>
<vals>
<n_vals>
<as_vals>
<ret_vals>
<assign>
<assign_val>
<term>
<args>
<n_args>
<arg_def_types>
<ret_func_types>
<ret_def_types>
<func_types>
<n_func_types>
<func_def_types>
<n_func_def_types>
<type>
<const>
*/
bool prog (p_data_ptr_t data);
bool main_b (p_data_ptr_t data);
bool stats (p_data_ptr_t data);
bool id_func (p_data_ptr_t data);
bool params (p_data_ptr_t data);
bool n_params (p_data_ptr_t data);
bool n_ids (p_data_ptr_t data);
bool vals (p_data_ptr_t data);
bool r_vals (p_data_ptr_t data);
bool n_vals (p_data_ptr_t data);
bool r_n_vals (p_data_ptr_t data);
bool as_vals (p_data_ptr_t data);
bool ret_vals (p_data_ptr_t data);
bool assign (p_data_ptr_t data);
bool assign_val (p_data_ptr_t data);
bool term (p_data_ptr_t data);
bool args (p_data_ptr_t data);
bool n_args (p_data_ptr_t data);
bool arg_def_types (p_data_ptr_t data);
bool ret_func_types (p_data_ptr_t data);
bool ret_def_types (p_data_ptr_t data);
bool func_types (p_data_ptr_t data);
bool n_func_types (p_data_ptr_t data);
bool func_def_types (p_data_ptr_t data);
bool a_n_func_def_types (p_data_ptr_t data);
bool r_n_func_def_types (p_data_ptr_t data);
bool type (p_data_ptr_t data);
bool constant (p_data_ptr_t data);
/***************** DATA FUNCTIONS ******************/
p_data_ptr_t create_data ()
{
return (p_data_ptr_t) malloc(sizeof(struct p_data));
}
void delete_data_param(function_params_t* param)
{
function_params_t* current = NULL;
while (param != NULL)
{
current = param;
param = param->param_next;
if (current->param_name != NULL)
{
current->param_name = NULL;
}
free(current);
current = NULL;
}
}
void delete_data_ret(function_returns_t* ret)
{
function_returns_t* current = NULL;
while (ret != NULL)
{
current = ret;
ret = ret->ret_next;
free(current);
current = NULL;
}
}
void delete_tbl_list_mem(LList* tbl_list)
{
free(tbl_list);
tbl_list = NULL;
}
void delete_data (p_data_ptr_t data)
{
delete_token(data->token);
free(data->func_name);
data->func_name = NULL;
free(data->body_func_name);
data->body_func_name = NULL;
delete_data_param(data->param);
delete_data_ret(data->ret);
delete_ids_list(data->ids_list);
free(data);
data = NULL;
}
void delete_symtable_data(symData_t** data)
{
paramDispose((*data)->first_param);
paramTypeDispose((*data)->first_type_param);
returnDefDispose((*data)->first_def_ret);
returnDispose((*data)->first_ret);
(*data)->first_param = NULL;
(*data)->first_type_param = NULL;
(*data)->first_def_ret = NULL;
(*data)->first_ret = NULL;
free(*data);
*data = NULL;
}
/**************** BACKEND FUNCTIONS ****************/
void next_token(p_data_ptr_t data)
{
delete_token(data->token);
data->token = get_next_token();
}
bool valid_token (token_t* token)
{
return (token != NULL || (token == NULL && err == E_NO_ERR));
}
bool expression (p_data_ptr_t data)
{
return psa(data);
}
/***** SYMBOL TABLE *****/
void create_tbl_list (LList* tbl_list)
{
if (tbl_list == NULL)
{
err = E_INTERNAL;
}
else
{
LL_Init(tbl_list);
}
}
void create_sym_table (LList* tbl_list)
{
symTree_t* tree = (symTree_t*) malloc(sizeof(symTree_t));
symTableInit(&tree);
LL_InsertLast(tbl_list, tree);
}
void create_symbol (symTree_t** tree, char* key)
{
symData_t* data = NULL;
symDataInit(&data);
if (err == E_NO_ERR)
{
symTableInsert(tree, key, data);
delete_symtable_data(&data);
data = NULL;
}
}
void insert_parameter (LList *tbl_list, char* func_name, char* id, data_type_t data_type)
{
/* Get global symbol table */
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
/* Get row for this function in global symbol table */
symData_t* tbl = symTableSearch(glb_tbl, func_name);
/* Insert Parameter */
paramInsert(tbl, data_type, id);
if (err != E_NO_ERR)
{
return;
}
/* Inc parameter count */
(tbl->params_count)++;
}
void insert_parameter_type (LList *tbl_list, char* func_name, data_type_t data_type)
{
/* Get global symbol table */
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
/* Get row for this function in global symbol table */
symData_t* tbl = symTableSearch(glb_tbl, func_name);
/* Insert Parameter */
paramTypeInsert(tbl, data_type);
if (err != E_NO_ERR)
{
return;
}
/* Inc parameter type count */
(tbl->params_type_count)++;
}
void insert_return (LList *tbl_list, char* func_name, data_type_t data_type)
{
/* Get global symbol table */
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
/* Get row for this function in global symbol table */
symData_t* tbl = symTableSearch(glb_tbl, func_name);
/* Insert Parameter */
returnInsert(tbl, data_type);
if (err != E_NO_ERR)
{
return;
}
/* Inc parameter count */
(tbl->returns_count)++;
}
void insert_def_return (LList *tbl_list, char* func_name, data_type_t data_type)
{
/* Get global symbol table */
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
/* Get row for this function in global symbol table */
symData_t* tbl = symTableSearch(glb_tbl, func_name);
/* Insert Parameter */
returnDefInsert(tbl, data_type);
if (err != E_NO_ERR)
{
return;
}
/* Inc parameter count */
(tbl->returns_def_count)++;
}
/***** SEMANTIC ANALYSIS *****/
/*
* Check first definition of identifier or function in table
*/
bool check_first_definition (symTree_t* table, char* identifier)
{
bool ret_val = false;
if (symTableSearch(table, identifier) == NULL)
{
ret_val = true;
}
return ret_val;
}
/*
* Check conflict that identifier hasnt same name as function
*/
bool check_conflict_id_func (LList* tbl_list, char* identifier)
{
bool ret_val = false;
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
if (symTableSearch(glb_tbl, identifier) == NULL)
{
ret_val = true;
}
return ret_val;
}
/*
* Check if function with the same name wasnt defined
*/
bool check_function_is_not_defined (LList* tbl_list, char* func_name)
{
bool ret_val = false;
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
symData_t* func_data = symTableSearch(glb_tbl, func_name);
if (func_data == NULL)
{
ret_val = true;
}
else
{
if (func_data->defined == false)
{
ret_val = true;
}
}
return ret_val;
}
bool check_no_multiple_function_declaration (LList* tbl_list, char* func_name)
{
bool ret_val = false;
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
symData_t* func_data = symTableSearch(glb_tbl, func_name);
if (func_data != NULL)
{
if (func_data->declared == false)
{
ret_val = true;
}
}
else
{
ret_val = true;
}
return ret_val;
}
/*
* Check if function with this name is declared
*/
bool check_function_is_declared (LList* tbl_list, char* func_name)
{
bool ret_val = false;
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
symData_t* func_data = symTableSearch(glb_tbl, func_name);
if (func_data != NULL)
{
if (func_data->declared == true)
{
ret_val = true;
}
}
return ret_val;
}
/*
* Check that identifier is declared
*/
bool check_identifier_is_declared (LList* tbl_list, char* id)
{
bool ret_val = false;
struct LLElement* elem = tbl_list->lastElement;
symData_t* table_elem;
/*
* Go through tables in linked list
*/
while (elem != NULL)
{
table_elem = symTableSearch(elem->root, id);
/*
* Check if identifier is in table
*/
if (table_elem != NULL)
{
if (table_elem->declared == true)
{
ret_val = true;
}
}
elem = elem->nextElement;
}
return ret_val;
}
/*
* Check that identifier is defined
*/
bool check_identifier_is_defined (LList* tbl_list, char* id)
{
bool ret_val = false;
struct LLElement* elem = tbl_list->lastElement;
symData_t* table_elem;
/*
* Go through tables in linked list
*/
while (elem != NULL)
{
table_elem = symTableSearch(elem->root, id);
/*
* Check if identifier is in table
*/
if (table_elem != NULL)
{
ret_val = true;
}
elem = elem->nextElement;
}
return ret_val;
}
void set_identifier_defined (LList* tbl_list, char* id)
{
struct LLElement* elem = tbl_list->lastElement;
symData_t* table_elem;
/*
* Go through tables in linked list
*/
while (elem != NULL)
{
table_elem = symTableSearch(elem->root, id);
if (table_elem != NULL)
{
table_elem->defined = true;
break;
}
elem = elem->nextElement;
}
}
data_type_t identifier_type (LList* tbl_list, char* id)
{
LLElementPtr elem = tbl_list->lastElement;
symData_t* table_elem;
data_type_t id_data_type = NIL;
/*
* Go through tables in linked list
*/
while (elem != NULL)
{
table_elem = symTableSearch(elem->root, id);
/*
* Check if identifier is in table
*/
if (table_elem != NULL)
{
id_data_type = table_elem->data_type;
break;
}
elem = elem->nextElement;
}
return id_data_type;
}
/*
* Check list of parameters of function declaration and function definition
*/
bool check_function_is_declared_before (LList* tbl_list, char* func_name)
{
bool ret_val = false;
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
symData_t* func_data = symTableSearch(glb_tbl, func_name);
if (func_data != NULL)
{
if (func_data->declared == true)
{
ret_val = true;
}
}
return ret_val;
}
bool check_function_dec_def_params_list (unsigned params_type_count,
function_params_t* first_type_param,
unsigned params_count,
function_params_t* first_param)
{
bool ret_val = true;
function_params_t* elem_declaration = NULL;
function_params_t* elem_definition = NULL;
/*
* Identical count of parameters
*/
if (params_type_count == params_count)
{
elem_declaration = first_type_param;
elem_definition = first_param;
while (elem_declaration != NULL && elem_definition != NULL)
{
if (elem_declaration->param_type != elem_definition->param_type)
{
ret_val = false;
break;
}
elem_declaration = elem_declaration->param_next;
elem_definition = elem_definition->param_next;
}
}
else
{
ret_val = false;
}
return ret_val;
}
bool check_function_dec_def_returns_list (unsigned returns_dec_count,
function_returns_t* first_dec_return,
unsigned returns_def_count,
function_returns_t* first_def_return)
{
bool ret_val = true;
function_returns_t* elem_declaration = NULL;
function_returns_t* elem_definition = NULL;
if (returns_dec_count == returns_def_count)
{
elem_declaration = first_dec_return;
elem_definition = first_def_return;
while (elem_declaration != NULL && elem_definition != NULL)
{
if (elem_declaration->return_type != elem_definition->return_type)
{
ret_val = false;
break;
}
elem_declaration = elem_declaration->ret_next;
elem_definition = elem_definition->ret_next;
}
}
else
{
ret_val = false;
}
return ret_val;
}
/*
* Check if function is declared but not defined then
*/
bool func_is_not_def (symTree_t* tree)
{
if (tree != NULL)
{
if (tree->data->declared == true && tree->data->defined == false)
{
return false;
}
else
{
if (!func_is_not_def(tree->nextLeft))
{
return false;
}
if (!func_is_not_def(tree->nextRight))
{
return false;
}
}
}
return true;
}
bool is_func(LList* tbl_list, char* id)
{
bool ret_val = false;
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
if (symTableSearch(glb_tbl, id) != NULL)
{
ret_val = true;
}
return ret_val;
}
void copy_params_to_func_table (LList* tbl_list, char* func_name)
{
//symTree_t* func_tbl = LL_GetLast(tbl_list);
symTree_t* glb_tbl = LL_GetFirst(tbl_list);
function_params_t* elem = symTableSearch(glb_tbl, func_name)->first_param;
symData_t* in_tbl_param_data;
while (elem != NULL)
{
/* INSERT PARAM TO FUNC TABLE */
create_symbol(&(tbl_list->lastElement->root), elem->param_name);
if (err != E_NO_ERR)
{
return;
}
// Get param in table data
in_tbl_param_data = symTableSearch(tbl_list->lastElement->root, elem->param_name);
// Add data type to param in table
in_tbl_param_data->data_type = elem->param_type;
// Set parameter as defined in table - because have value from function call
in_tbl_param_data->defined = true;
/* END OF INSERT */
elem = elem->param_next;
}
}
bool check_func_assign (p_data_ptr_t data)
{
bool ret_val = true;
function_returns_t* func_returns = symTableSearch(LL_GetFirst(data->tbl_list), data->func_name)->first_ret;
while (func_returns != NULL && data->ids_list != NULL)
{
if (func_returns->return_type != data->ids_list->type)
{
if (func_returns->return_type == NIL ||
(data->ids_list->type == NUMBER && func_returns->return_type == INT))
{
// VALID
}
else
{
err = E_SEM_PARAM;
ret_val = false;
break;
}
}
set_identifier_defined(data->tbl_list, data->ids_list->id);
func_returns = func_returns->ret_next;
free(data->ids_list->id);
data->ids_list->id = NULL;
data->ids_list = data->ids_list->next;
}
/* The function returns fewer values than the variables expect */
if (func_returns == NULL && data->ids_list != NULL)
{
err = E_SEM_PARAM;
ret_val = false;
}
return ret_val;
}
void create_tbl_list_mem (LList** tbl_list)
{
*tbl_list = (LList*) malloc(sizeof(LList));
if (*tbl_list == NULL)
{
err = E_INTERNAL;
}
}
bool push_params_code_gen(p_data_ptr_t data)
{
param_type_t* param_type = NULL;
param_attribute_t* param_attr = NULL;
param_type = (param_type_t*) malloc(sizeof(param_type_t));
if (param_type == NULL)
{
err = E_INTERNAL;
return false;
}
param_attr = (param_attribute_t*) malloc(sizeof(union param_attribute));
if (param_attr == NULL)
{
free(param_type);
param_type = NULL;
err = E_INTERNAL;
return false;
}
while (param_stack_pop(data->stack, param_type, param_attr))
{
switch (*param_type)
{
case P_ID:
codeGen_push_var(param_attr->id);
break;
case P_INT:
codeGen_push_int(param_attr->integer);
break;
case P_NUMBER:
codeGen_push_float(param_attr->number);
break;
case P_STR:
codeGen_push_string(param_attr->str);
break;
case P_NIL:
codeGen_push_nil();
break;
default:
break;
}
}
param_stack_dispose(data->stack);
if (*param_type == P_ID)
{
free(param_attr->id);
param_attr->id = NULL;
}
else if (*param_type == P_STR)
{
free(param_attr->str);
param_attr->str = NULL;
}
free(param_attr);
param_attr = NULL;
free(param_type);
param_type = NULL;
return true;
}
void insert_built_in_functions (LList* tbl_list)
{
tbl_list = tbl_list;
symTree_t* glb_tbl = NULL;
// function reads (): string
symData_t* data = NULL;
symDataInit(&data);
data->defined = true;
data->returns_count = 1;
returnInsert(data, STR);
symTableInsert(&glb_tbl, "reads", data);
delete_symtable_data(&data);
data = NULL;
// function readi (): integer
symDataInit(&data);
data->defined = true;
data->returns_count = 1;
returnInsert(data, INT);
symTableInsert(&glb_tbl, "readi", data);
delete_symtable_data(&data);
data = NULL;
// function readn (): number
symDataInit(&data);
data->defined = true;
data->returns_count = 1;
returnInsert(data, NUMBER);
symTableInsert(&glb_tbl, "readn", data);
delete_symtable_data(&data);
data = NULL;
// function write (term_1, term_2, ..., term_n)
symDataInit(&data);
data->defined = true;
symTableInsert(&glb_tbl, "write", data);
delete_symtable_data(&data);
data = NULL;
// function tointeger (f : number) : integer
symDataInit(&data);
data->defined = true;
data->returns_count = 1;
data->params_count = 1;
paramInsert(data, NUMBER, "f");
returnInsert(data, INT);
symTableInsert(&glb_tbl, "tointeger", data);
delete_symtable_data(&data);
data = NULL;
// function substr (s : string, i : number, j : number) : string
symDataInit(&data);
data->defined = true;
data->returns_count = 1;
data->params_count = 3;
paramInsert(data, STR, "s");
paramInsert(data, NUMBER, "i");
paramInsert(data, NUMBER, "j");
returnInsert(data, STR);
symTableInsert(&glb_tbl, "substr", data);
delete_symtable_data(&data);
data = NULL;
// function ord (s : string, i : integer) : integer
symDataInit(&data);
data->defined = true;
data->returns_count = 1;
data->params_count = 2;
paramInsert(data, STR, "s");
paramInsert(data, INT, "i");
returnInsert(data, INT);
symTableInsert(&glb_tbl, "ord", data);
delete_symtable_data(&data);
data = NULL;
// function chr (i : integer) : string
symDataInit(&data);
data->defined = true;
data->returns_count = 1;
data->params_count = 1;
paramInsert(data, INT, "i");
returnInsert(data, STR);
symTableInsert(&glb_tbl, "chr", data);
delete_symtable_data(&data);
data = NULL;
tbl_list->lastElement->root = glb_tbl;
/* -------------- CODE GEN --------------*/
codeGen_built_in_function();
/* ----------- END OF CODE GEN ----------*/
}
/******************* PARSER MAIN *******************/
/*
* Parser main function
*/
parser_error_t parser ()
{
err = E_NO_ERR;
p_data_ptr_t data;
data = create_data();
if (!data)
{
err = E_INTERNAL;
delete_data(data);
return PARSE_ERR;
}
data->token = get_next_token();
if (!valid_token(data->token))
{
err = E_SYNTAX;
delete_data(data);
return PARSE_ERR;
}
/* -------------- SEMANTIC --------------*/
create_tbl_list_mem(&(data->tbl_list));
if (err != E_NO_ERR)
{
return PARSE_ERR;
}
// Create linked list with symbol tables
create_tbl_list(data->tbl_list);
if (err != E_NO_ERR)
{
return PARSE_ERR;
}
// Create global symbol table
create_sym_table(data->tbl_list);
/* ----------- END OF SEMANTIC ----------*/
if (!prog(data))
{
if (err == E_NO_ERR)
{
err = E_SYNTAX;
}
delete_tbl_list_mem(data->tbl_list);
delete_data(data);
return PARSE_ERR;
}
delete_tbl_list_mem(data->tbl_list);
delete_data(data);
return PARSE_NO_ERR;
}
/*************** NON-TERMINALS RULES ***************/
/*
* NON-TERMINAL: <prog>
*
* RULES:
* 1. <prog> -> require “ifj21” <main_b>
*/
bool prog (p_data_ptr_t data)
{
bool ret_val = false;
token_type_t token_type;