-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.c
947 lines (887 loc) · 36.9 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
#include "parser.h"
#include "lex_analyzer.h"
#include "error_manager.h"
/****************************************************************************************
********************************* FIRST SET *********************************************
****************************************************************************************/
int First_Program[] = {CLASS, TYPEDEF, EOF_TOKEN, INT, FLOAT, BOOL, ID, CHAR, '\0'};
int First_ProgramFat[] = {LPAREN, LBRACKET, COMMA, SEMICOLON, '\0'};
int First_ProgramClass[] = {LBRACE, COLON, '\0'};
int First_VarStmt[] = {ID, INT, FLOAT, BOOL, CHAR, IF, WHILE, SWITCH, BREAK, PRINT, READLN, RETURN, THROW, LBRACE, TRY,
MINUS, BANG, PLUS, MULT, AND_BIT, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE, THIS,
NEW, '\0'};
int First_VarStmtAux[] = {LPAREN, MULT, ID, SEMICOLON, PERIOD, POINTER, LBRACKET, ASSIGN, ALTERNATIVE, AND, EQUAL,
NOTEQUAL, LTE, GTE, LT, GT, PLUS, MINUS, ALTERNATIVE_BIT, DIV, MOD, AND_BIT, '\0'};
int First_LocalDecl[] = {PUBLIC, PRIVATE, INT, FLOAT, BOOL, ID, CHAR, '\0'};
int First_LocalDeclFat[] = {LPAREN, LBRACKET, COMMA, SEMICOLON, '\0'};
int First_VarDecl[] = {INT, FLOAT, BOOL, ID, CHAR, '\0'};
int First_IdList[] = {MULT, ID, '\0'};
int First_IdListRR[] = {COMMA, '\0'};
int First_Pointer[] = {MULT, '\0'};
int First_Array[] = {LBRACKET, '\0'};
int First_Matrix[] = {LBRACKET, '\0'};
int First_FormalList[] = {INT, FLOAT, BOOL, ID, CHAR, '\0'};
int First_FormalRest[] = {COMMA, '\0'};
int First_Type[] = {INT, FLOAT, BOOL, ID, CHAR, '\0'};
int First_TypePrimitive[] = {INT, FLOAT, BOOL, CHAR, '\0'};
int First_StmtList[] = {IF, WHILE, SWITCH, BREAK, PRINT, READLN, RETURN, THROW, LBRACE, TRY, MINUS, BANG, PLUS, MULT,
AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE, THIS, NEW, '\0'};
int First_Stmt[] = {IF, WHILE, SWITCH, BREAK, PRINT, READLN, RETURN, THROW, LBRACE, TRY, MINUS, BANG, PLUS, MULT,
AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE, THIS, NEW, '\0'};
int First_Else[] = {ELSE, '\0'};
int First_CaseBlock[] = {CASE, '\0'};
int First_CaseBlockAux[] = {CASE, IF, WHILE, SWITCH, BREAK, PRINT, READLN, RETURN, THROW, LBRACE, TRY, MINUS, BANG,
PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE, THIS, NEW,
'\0'};
int First_ExprList[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE,
THIS, NEW, '\0'};
int First_ExprListTail[] = {COMMA, '\0'};
int First_ExprAttribution[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE,
FALSE, THIS, NEW, '\0'};
int First_ExprAttributionAux[] = {ASSIGN, '\0'};
int First_ExprAlternative[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE,
FALSE, THIS, NEW, '\0'};
int First_ExprAlternativeAux[] = {ALTERNATIVE, '\0'};
int First_ExprAnd[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE,
THIS, NEW, '\0'};
int First_ExprAndAux[] = {AND, '\0'};
int First_ExprEquality[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE,
FALSE, THIS, NEW, '\0'};
int First_ExprEqualityAux[] = {EQUAL, NOTEQUAL, '\0'};
int First_ExprRelational[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE,
FALSE, THIS, NEW, '\0'};
int First_ExprRelationalAux[] = {LTE, GTE, LT, GT, '\0'};
int First_ExprAdd[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE,
THIS, NEW, '\0'};
int First_ExprAddAux[] = {PLUS, MINUS, ALTERNATIVE_BIT, '\0'};
int First_ExprMult[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE,
THIS, NEW, '\0'};
int First_ExprMultAux[] = {MULT, DIV, MOD, AND_BIT, '\0'};
int First_ExprUnary[] = {MINUS, BANG, PLUS, MULT, AND_BIT, ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE,
THIS, NEW, '\0'};
int First_Primary[] = {ID, LPAREN, INTEGER, REAL, CHARACTER, LITERAL, TRUE, FALSE, THIS, NEW, '\0'};
int First_PrimaryFat[] = {LPAREN, PERIOD, POINTER, LBRACKET, '\0'};
int First_FieldAccess[] = {PERIOD, POINTER, LBRACKET, '\0'};
/****************************************************************************************
******************************** FIRST SET END ******************************************
****************************************************************************************/
/****************************************************************************************
********************************** SYNC SET *********************************************
****************************************************************************************/
int Sync_Program[] = {EOF_TOKEN, CLASS, TYPEDEF, INT, FLOAT, BOOL, ID, CHAR, '\0'};
int Sync_ProgramFat[] = {EOF_TOKEN, CLASS, TYPEDEF, INT, FLOAT, BOOL, ID, CHAR, LBRACE, '\0'};
int Sync_ProgramClass[] = {EOF_TOKEN, CLASS, TYPEDEF, INT, FLOAT, BOOL, ID, CHAR, PUBLIC, PRIVATE, '\0'};
int Sync_VarStmt[] = {EOF_TOKEN, RBRACE, SEMICOLON, '\0'};
int Sync_VarStmtAux[] = {EOF_TOKEN, RBRACE, SEMICOLON, '\0'};
int Sync_LocalDecl[] = {EOF_TOKEN, RBRACE, '\0'};
int Sync_LocalDeclFat[] = {EOF_TOKEN, RBRACE, SEMICOLON, '\0'};
int Sync_VarDecl[] = {EOF_TOKEN, RBRACE, SEMICOLON, '\0'};
int Sync_IdList[] = {EOF_TOKEN, SEMICOLON, COMMA, RBRACE, '\0'};
int Sync_IdListRR[] = {EOF_TOKEN, SEMICOLON, RBRACE, COMMA, '\0'};
int Sync_Pointer[] = {EOF_TOKEN, ID, '\0'};
int Sync_Array[] = {EOF_TOKEN, COMMA, CLASS, TYPEDEF, INT, FLOAT, BOOL, ID, CHAR, SEMICOLON, RBRACE, RBRACKET,
'\0'};
int Sync_FormalList[] = {EOF_TOKEN, RPAREN, COMMA, '\0'};
int Sync_FormalRest[] = {EOF_TOKEN, RPAREN, COMMA, '\0'};
int Sync_Type[] = {EOF_TOKEN, MULT, EOF_TOKEN, ID, SEMICOLON, RBRACE, RPAREN, '\0'};
int Sync_TypePrimitive[] = {EOF_TOKEN, MULT, RBRACE, ID, SEMICOLON, '\0'};
int Sync_StmtList[] = {EOF_TOKEN, ID, RBRACE, INT, FLOAT, BOOL, CHAR, IF, WHILE, SWITCH, BREAK, PRINT, READLN, RETURN,
THROW, LBRACE, TRY, MINUS, BANG, PLUS, MULT, AND_BIT, LPAREN, INTEGER, REAL, CHARACTER, LITERAL,
TRUE, FALSE, THIS, NEW, CASE, '\0'};
int Sync_Stmt[] = {EOF_TOKEN, ID, RBRACE, INT, FLOAT, BOOL, CHAR, IF, WHILE, SWITCH, BREAK, PRINT, READLN, RETURN,
THROW, LBRACE, TRY, MINUS, BANG, PLUS, MULT, AND_BIT, LPAREN, INTEGER, REAL, CHARACTER, LITERAL,
TRUE, FALSE, THIS, NEW, ELSE, CATCH, CASE, '\0'};
int Sync_Else[] = {EOF_TOKEN, ID, RBRACE, INT, FLOAT, BOOL, CHAR, IF, WHILE, SWITCH, BREAK, PRINT, READLN, RETURN,
THROW, LBRACE, TRY, MINUS, BANG, PLUS, MULT, AND_BIT, LPAREN, INTEGER, REAL, CHARACTER, LITERAL,
TRUE, FALSE, THIS, NEW, ELSE, CATCH, CASE, '\0'};
int Sync_CaseBlock[] = {EOF_TOKEN, RBRACE, CASE, '\0'};
int Sync_CaseBlockAux[] = {EOF_TOKEN, RBRACE, '\0'};
int Sync_ExprList[] = {EOF_TOKEN, RPAREN, '\0'};
int Sync_ExprListTail[] = {EOF_TOKEN, RPAREN, '\0'};
int Sync_Expr[] = {EOF_TOKEN, RPAREN, SEMICOLON, COMMA, RBRACKET, '\0'};
int Sync_ExprAttribution[] = {EOF_TOKEN, RPAREN, SEMICOLON, COMMA, ALTERNATIVE, RBRACE, AND, EQUAL, NOTEQUAL, LTE, GTE,
LT, GT, PLUS, MINUS, ALTERNATIVE_BIT, MULT, DIV, MOD, AND_BIT, RBRACKET, '\0'};
int Sync_ExprAtributionAux[] = {EOF_TOKEN, ALTERNATIVE, RBRACE, AND, EQUAL, NOTEQUAL, LTE, GTE, LT, GT, PLUS, MINUS,
ALTERNATIVE_BIT, MULT, DIV, MOD, AND_BIT, SEMICOLON, RPAREN, COMMA, RBRACKET, '\0'};
int Sync_ExprAlternative[] = {EOF_TOKEN, ASSIGN, RPAREN, SEMICOLON, COMMA, AND, RBRACE, EQUAL, NOTEQUAL, LTE, GTE, LT,
GT, PLUS, MINUS, ALTERNATIVE_BIT, MULT, DIV, MOD, AND_BIT, ALTERNATIVE, RBRACKET, '\0'};
int Sync_ExprAlternativeAux[] = {EOF_TOKEN, AND, RBRACE, EQUAL, NOTEQUAL, LTE, GTE, LT, GT, PLUS, MINUS,
ALTERNATIVE_BIT, MULT, DIV, MOD, AND_BIT, SEMICOLON, ASSIGN, RPAREN, COMMA,
ALTERNATIVE, RBRACKET, '\0'};
int Sync_ExprAnd[] = {EOF_TOKEN, ALTERNATIVE, ASSIGN, RPAREN, SEMICOLON, COMMA, EQUAL, NOTEQUAL, RBRACE, LTE, GTE, LT,
GT, PLUS, MINUS, ALTERNATIVE_BIT, MULT, DIV, MOD, AND_BIT, AND, RBRACKET, '\0'};
int Sync_ExprAndAux[] = {EOF_TOKEN, EQUAL, NOTEQUAL, RBRACE, LTE, GTE, LT, GT, PLUS, MINUS, ALTERNATIVE_BIT, MULT, DIV,
MOD, AND_BIT, SEMICOLON, ALTERNATIVE, ASSIGN, RPAREN, COMMA, AND, RBRACKET, '\0'};
int Sync_ExprEquality[] = {EOF_TOKEN, AND, ALTERNATIVE, ASSIGN, RPAREN, SEMICOLON, COMMA, LTE, GTE, LT, GT, RBRACE,
PLUS, MINUS, ALTERNATIVE_BIT, MULT, DIV, MOD, AND_BIT, EQUAL, NOTEQUAL, RBRACKET, '\0'};
int Sync_ExprEqualityAux[] = {EOF_TOKEN, LTE, GTE, LT, GT, RBRACE, PLUS, MINUS, ALTERNATIVE_BIT, MULT, DIV, MOD,
AND_BIT, SEMICOLON, AND, ALTERNATIVE, ASSIGN, RPAREN, COMMA, EQUAL, NOTEQUAL, RBRACKET,
'\0'};
int Sync_ExprRelational[] = {EOF_TOKEN, EQUAL, NOTEQUAL, AND, ALTERNATIVE, ASSIGN, RPAREN, SEMICOLON, COMMA, PLUS,
MINUS, ALTERNATIVE_BIT, RBRACE, MULT, DIV, MOD, AND_BIT, LTE, GTE, LT, GT, RBRACKET, '\0'};
int Sync_ExprRelationalAux[] = {EOF_TOKEN, PLUS, MINUS, ALTERNATIVE_BIT, RBRACE, MULT, DIV, MOD, AND_BIT, SEMICOLON,
EQUAL, NOTEQUAL, AND, ALTERNATIVE, ASSIGN, RPAREN, COMMA, LTE, GTE, LT, GT, RBRACKET,
'\0'};
int Sync_ExprAdd[] = {EOF_TOKEN, LTE, GTE, LT, GT, EQUAL, NOTEQUAL, AND, ALTERNATIVE, ASSIGN, RPAREN, SEMICOLON, COMMA,
MULT, DIV, MOD, AND_BIT, RBRACE, PLUS, MINUS, ALTERNATIVE_BIT, RBRACKET, '\0'};
int Sync_ExprAddAux[] = {EOF_TOKEN, MULT, DIV, MOD, AND_BIT, RBRACE, SEMICOLON, LTE, GTE, LT, GT, EQUAL, NOTEQUAL, AND,
ALTERNATIVE, ASSIGN, RPAREN, COMMA, PLUS, MINUS, ALTERNATIVE_BIT, RBRACKET, '\0'};
int Sync_ExprMult[] = {EOF_TOKEN, PLUS, MINUS, ALTERNATIVE_BIT, LTE, GTE, LT, GT, EQUAL, NOTEQUAL, AND, ALTERNATIVE,
ASSIGN, RPAREN, SEMICOLON, COMMA, MULT, DIV, MOD, AND_BIT, RBRACE, RBRACKET, '\0'};
int Sync_ExprMultAux[] = {EOF_TOKEN, SEMICOLON, PLUS, MINUS, ALTERNATIVE_BIT, LTE, GTE, LT, GT, EQUAL, NOTEQUAL, AND,
ALTERNATIVE, ASSIGN, RPAREN, COMMA, MULT, DIV, MOD, AND_BIT, RBRACE, RBRACKET, '\0'};
int Sync_ExprUnary[] = {EOF_TOKEN, MULT, DIV, MOD, AND_BIT, PLUS, MINUS, ALTERNATIVE_BIT, LTE, GTE, LT, GT, EQUAL,
NOTEQUAL, AND, ALTERNATIVE, ASSIGN, RPAREN, SEMICOLON, COMMA, RBRACE, RBRACKET, '\0'};
int Sync_Primary[] = {EOF_TOKEN, MULT, DIV, MOD, AND_BIT, PLUS, MINUS, ALTERNATIVE_BIT, LTE, GTE, LT, GT, EQUAL,
NOTEQUAL, AND, ALTERNATIVE, ASSIGN, RPAREN, SEMICOLON, COMMA, RBRACE, RBRACKET, '\0'};
int Sync_PrimaryFat[] = {EOF_TOKEN, ASSIGN, RBRACE, ALTERNATIVE, AND, EQUAL, NOTEQUAL, LTE, GTE, LT, GT, PLUS, MINUS,
ALTERNATIVE_BIT, MULT, DIV, MOD, AND_BIT, SEMICOLON, RPAREN, COMMA, RBRACKET, '\0'};
int Sync_FieldAccess[] = {EOF_TOKEN, MULT, DIV, MOD, AND_BIT, PLUS, MINUS, ALTERNATIVE_BIT, LTE, GTE, LT, GT, EQUAL,
NOTEQUAL, AND, ALTERNATIVE, ASSIGN, RPAREN, SEMICOLON, COMMA, RBRACE, RBRACKET, '\0'};
/****************************************************************************************
********************************** SYNC SET END *****************************************
****************************************************************************************/
int lookahead;
ProgramNode *program;
PrintASTVisitor *visitor;
ProgramNode *
Program(ClassListNode *class_list, TypeListNode *type_list, VarFuncListNode *var_func_list);
VarFuncListNode *ProgramFat(TypeNode *type, PointerNode *pointer, IdentifierNode *id, VarFuncListNode *var_func);
ClassListNode *ProgramClass(IdentifierNode *id, ClassListNode *class_list);
VarFuncListNode *LocalDecl();
VarFuncListNode *LocalDeclFat(TypeNode *type, PointerNode *pointer, IdentifierNode *id);
VarStmtNode *VarStmt();
VarStmtNode *VarStmtAux(IdentifierNode *id);
VarDeclNode *VarDecl();
IdListNode *IdList();
IdListNode *IdListRR();
PointerNode *Pointer();
ArrayDeclNode *Array();
FormalListNode *FormalList();
FormalListNode *FormalRest();
TypeNode *Type();
TypeNode *TypePrimitive();
StatementListNode *StmtList();
StatementNode *Stmt();
StatementNode *Else();
CaseBlockNode *CaseBlock();
CaseBlockNode *CaseBlockAux(IntegerNode *integer);
ExpListNode *ExprList();
ExpListNode *ExprListTail();
ExpNode *ExprAttribution();
ExpNode *ExprAttributionAux(ExpNode *expr);
ExpNode *ExprAlternative();
ExpNode *ExprAlternativeAux(ExpNode *expr);
ExpNode *ExprAnd();
ExpNode *ExprAndAux(ExpNode *expr);
ExpNode *ExprEquality();
ExpNode *ExprEqualityAux(ExpNode *expr);
ExpNode *ExprRelational();
ExpNode *ExprRelationalAux(ExpNode *expr);
ExpNode *ExprAdd();
ExpNode *ExprAddAux(ExpNode *expr);
ExpNode *ExprMult();
ExpNode *ExprMultAux(ExpNode *expr);
ExpNode *ExprUnary();
ExpNode *Primary();
ExpNode *PrimaryFat(IdentifierNode *id);
ExpNode *FieldAccess();
/** Starts parser function with the first production
* lookahead variable gets the first token from 'lex.analyzer.c'
*/
ProgramNode *init_parser() {
lookahead = get_token();
program = Program(NULL, NULL, NULL);
visitor = new PrintASTVisitor();
program->accept(visitor);
return program;
}
void end_parser() {
delete visitor;
delete program;
}
/**
* Return 1 if lookahead is equal to a symbol in the set "first" passed
*/
int contains_lookahead(const int *first_set) {
for (int i = 0; first_set[i] != '\0'; i++)
if (lookahead == first_set[i]) return 1;
return 0;
}
/**
* Return lookahead variable
*/
int get_lookahead() {
return lookahead;
}
/** Print the token matched
* lookahead variable gets the next token from 'lex.analyzer.c'
*/
void eat_token() {
/*if (lookahead == LITERAL || lookahead == INTEGER || lookahead == REAL || lookahead == ID ||
lookahead == CHARACTER)
printf("\nMATCH: %stmt.%stmt", get_token_name(lookahead), lexeme_name());
else
printf("\nMATCH: %stmt", get_token_name(lookahead));*/
lookahead = get_token();
}
/****************************************************************************************
********************************* PRODUCTIONS *******************************************
****************************************************************************************/
ProgramNode *
Program(ClassListNode *class_list, TypeListNode *type_list, VarFuncListNode *var_func_list) {
// printf("\nProgram");
int line = get_line();
if (lookahead == TYPEDEF) {
eat_token();
eat_or_skip(STRUCT, Sync_Program);
eat_or_skip(LBRACE, Sync_Program);
TypeNode *type = Type();
IdListNode *id_list = IdList();
eat_or_skip(SEMICOLON, Sync_Program);
VarDeclNode *var_decl = new VarDeclNode(type, id_list, VarDecl(), line);
eat_or_skip(RBRACE, Sync_Program);
const char *aux = eat_or_skip(ID, Sync_Program);
IdentifierNode *id = new IdentifierNode(aux, line);
eat_or_skip(SEMICOLON, Sync_Program);
type_list = new TypeListNode(var_decl, id, type_list, line);
return Program(class_list, type_list, var_func_list);
} else if (lookahead == CLASS) {
eat_token();
const char *aux = eat_or_skip(ID, Sync_Program);
IdentifierNode *id = new IdentifierNode(aux, line);
return Program(ProgramClass(id, class_list), type_list, var_func_list);
} else if (contains_lookahead(First_Type)) {
TypeNode *type = Type();
PointerNode *pointer = Pointer();
const char *aux = eat_or_skip(ID, Sync_Program);
IdentifierNode *id = new IdentifierNode(aux, line);
return Program(class_list, type_list, ProgramFat(type, pointer, id, var_func_list));
} else if (lookahead == EOF_TOKEN) {
eat_token();
return new ProgramNode(class_list, type_list, var_func_list, line); ///END OF FILE - return program node
} else
synchronize(ERROR_UNEXPECTED_TOKEN, Sync_Program);
return Program(class_list, type_list, var_func_list);
}
VarFuncListNode *ProgramFat(TypeNode *type, PointerNode *pointer, IdentifierNode *id, VarFuncListNode *var_func) {
// printf("\nProgramFat");
int line = get_line();
if (lookahead == LPAREN) {
eat_token();
FormalListNode *formal_list = FormalList();
eat_or_skip(RPAREN, Sync_ProgramFat);
eat_or_skip(LBRACE, Sync_ProgramFat);
VarStmtNode *var_stmt = VarStmt();
eat_or_skip(RBRACE, Sync_ProgramFat);
return new VarFuncListNode(new FunctionDeclNode(type, pointer, id, formal_list, var_stmt, var_func, line),
line);
} else {
ArrayDeclNode *array = Array();
IdListNode *list = IdListRR();
eat_or_skip(SEMICOLON, Sync_ProgramFat);
return new VarFuncListNode(
new VarDeclNode(type, new IdListNode(pointer, id, array, list, line), var_func, line),
line);
}
}
ClassListNode *ProgramClass(IdentifierNode *id, ClassListNode *class_list) {
// printf("\nProgramClass");
int line = get_line();
if (lookahead == LBRACE) {
eat_token();
VarFuncListNode *var_func = LocalDecl();
eat_or_skip(RBRACE, Sync_ProgramClass);
eat_or_skip(SEMICOLON, Sync_ProgramClass);
return new ClassListNode(id, var_func, NULL, class_list, line);
} else if (lookahead == COLON) {
eat_token();
const char *aux = eat_or_skip(ID, Sync_ProgramClass);
IdentifierNode *id_parent = new IdentifierNode(aux, line);
eat_or_skip(LBRACE, Sync_ProgramClass);
VarFuncListNode *var_func = LocalDecl();
eat_or_skip(RBRACE, Sync_ProgramClass);
eat_or_skip(SEMICOLON, Sync_ProgramClass);
return new ClassListNode(id, var_func, id_parent, class_list, line);
} else
synchronize(ERROR_LBRACE_OR_COLON_EXPECTED, Sync_ProgramClass);
return NULL;
}
VarFuncListNode *LocalDecl() {
// printf("\nLocalDecl");
int line = get_line();
if (contains_lookahead(First_Type)) {
TypeNode *type = Type();
PointerNode *pointer = Pointer();
const char *aux = eat_or_skip(ID, Sync_LocalDecl);
IdentifierNode *id = new IdentifierNode(aux, line);
return LocalDeclFat(type, pointer, id);
} else if (lookahead == PUBLIC || lookahead == PRIVATE) {
eat_token();
eat_or_skip(COLON, Sync_LocalDecl);
return LocalDecl();
}
///else epsilon
return NULL;
}
VarFuncListNode *LocalDeclFat(TypeNode *type, PointerNode *pointer, IdentifierNode *id) {
// printf("\nLocalDeclFat");
int line = get_line();
if (lookahead == LPAREN) {
eat_token();
FormalListNode *formal_list = FormalList();
eat_or_skip(RPAREN, Sync_LocalDeclFat);
eat_or_skip(LBRACE, Sync_LocalDeclFat);
VarStmtNode *var_stmt = VarStmt();
eat_or_skip(RBRACE, Sync_LocalDeclFat);
return new VarFuncListNode(new FunctionDeclNode(type, pointer, id, formal_list, var_stmt, LocalDecl(), line),
line);
} else {
ArrayDeclNode *array = Array();
IdListNode *list = IdListRR();
eat_or_skip(SEMICOLON, Sync_LocalDeclFat);
return new VarFuncListNode(
new VarDeclNode(type, new IdListNode(pointer, id, array, list, line), LocalDecl(), line),
line);
}
}
VarStmtNode *VarStmt() {
// printf("\nVarStmt");
int line = get_line();
if (lookahead == ID) {
IdentifierNode *id = new IdentifierNode(get_lexeme(), line);
eat_token();
return VarStmtAux(id);
} else if (contains_lookahead(First_TypePrimitive)) {
TypeNode *primitive = TypePrimitive();
IdListNode *list = IdList();
eat_or_skip(SEMICOLON, Sync_VarStmt);
return new VarStmtNode(new VarDeclNode(primitive, list, line), VarStmt(), line);
} else if (contains_lookahead(First_StmtList))
return new VarStmtNode(StmtList(), VarStmt(), line);
///else epsilon
return NULL;
}
VarStmtNode *VarStmtAux(IdentifierNode *id) {
// printf("\nVarStmtAux");
int line = get_line();
if (contains_lookahead(First_IdList)) {
IdListNode *list = IdList();
eat_or_skip(SEMICOLON, Sync_VarStmtAux);
TypeNode *type = new TypeNode(ID, id->get_lexeme(), line);
return new VarStmtNode(new VarDeclNode(type, list, line), VarStmt(), line);
} else if (contains_lookahead(First_PrimaryFat) || contains_lookahead(First_ExprAttributionAux)
|| contains_lookahead(First_ExprAlternativeAux) || contains_lookahead(First_ExprAndAux)
|| contains_lookahead(First_ExprEqualityAux) || contains_lookahead(First_ExprRelationalAux)
|| contains_lookahead(First_ExprAddAux) || contains_lookahead(First_ExprMultAux)) {
ExpNode *exp = new PrimaryNode(id, PrimaryFat(id), line);
exp = ExprAttributionAux(exp);
exp = ExprAlternativeAux(exp);
exp = ExprAndAux(exp);
exp = ExprEqualityAux(exp);
exp = ExprRelationalAux(exp);
exp = ExprAddAux(exp);
exp = ExprMultAux(exp);
eat_or_skip(SEMICOLON, Sync_VarStmtAux);
return new VarStmtNode(new StatementListNode(exp, StmtList(), line), NULL, line);
} else
synchronize(ERROR_UNEXPECTED_TOKEN, Sync_VarStmtAux);
return NULL;
}
VarDeclNode *VarDecl() {
// printf("\nVarDecl");
int line = get_line();
if (contains_lookahead(First_Type)) {
TypeNode *type = Type();
IdListNode *list = IdList();
eat_or_skip(SEMICOLON, Sync_VarDecl);
return new VarDeclNode(type, list, VarDecl(), line);
}
///else epsilon
return NULL;
}
IdListNode *IdList() {
// printf("\nIdList");
int line = get_line();
PointerNode *pointer = Pointer();
const char *aux = eat_or_skip(ID, Sync_IdList);
IdentifierNode *id = new IdentifierNode(aux, line);
return new IdListNode(pointer, id, Array(), IdListRR(), line);
}
IdListNode *IdListRR() {
// printf("\nIdListRR");
int line = get_line();
if (lookahead == COMMA) {
eat_token();
PointerNode *pointer = Pointer();
const char *aux = eat_or_skip(ID, Sync_IdListRR);
return new IdListNode(pointer, new IdentifierNode(aux, line), Array(), IdListRR(), line);
}
///else epsilon
return NULL;
}
PointerNode *Pointer() {
// printf("\nPointer");
int line = get_line();
if (lookahead == MULT) {
eat_token();
return new PointerNode(line);
}
///else epsilon
return NULL;
}
ArrayDeclNode *Array() {
// printf("\nArray");
int line = get_line();
if (lookahead == LBRACKET) {
eat_token();
const char *aux = eat_or_skip(INTEGER, Sync_Array);
IntegerNode *integer = new IntegerNode(aux, line);
eat_or_skip(RBRACKET, Sync_Array);
return new ArrayDeclNode(integer, line);
}
///else epsilon
return NULL;
}
FormalListNode *FormalList() {
// printf("\nFormalList");
int line = get_line();
if (contains_lookahead(First_Type)) {
TypeNode *type = Type();
PointerNode *pointer = Pointer();
const char *aux = eat_or_skip(ID, Sync_FormalList);
IdentifierNode *id = new IdentifierNode(aux, line);
ArrayDeclNode *array = Array();
return new FormalListNode(type, pointer, id, array, FormalRest(), line);
}
///else epsilon
return NULL;
}
FormalListNode *FormalRest() {
// printf("\nFormalRest");
int line = get_line();
if (lookahead == COMMA) {
eat_token();
TypeNode *type = Type();
PointerNode *pointer = Pointer();
const char *aux = eat_or_skip(ID, Sync_FormalRest);
IdentifierNode *id = new IdentifierNode(aux, line);
ArrayDeclNode *array = Array();
return new FormalListNode(type, pointer, id, array, FormalRest(), line);
}
///else epsilon
return NULL;
}
TypeNode *Type() {
// printf("\nType");
int line = get_line();
if (contains_lookahead(First_Type)) {
TypeNode *type;
type = new TypeNode(lookahead, lookahead == ID ? get_lexeme() : get_token_name(lookahead), line);
eat_token();
return type;
} else
synchronize(ERROR_TYPE_EXPECTED, Sync_Type);
return NULL;
}
TypeNode *TypePrimitive() {
// printf("\nTypePrimitive");
int line = get_line();
if (contains_lookahead(First_TypePrimitive)) {
TypeNode *type = new TypeNode(lookahead, get_token_name(lookahead), line);
eat_token();
return type;
} else
synchronize(ERROR_TYPE_PRIMITIVE_EXPECTED, Sync_TypePrimitive);
return NULL;
}
StatementListNode *StmtList() {
// printf("\nStmtList");
int line = get_line();
if (contains_lookahead(First_Stmt)) {
return new StatementListNode(Stmt(), StmtList(), line);
}
return NULL;
}
StatementNode *Stmt() {
// printf("\nStmt");
int line = get_line();
if (lookahead == IF) {
eat_token();
eat_or_skip(LPAREN, Sync_Stmt);
ExpNode *expr = ExprAttribution();
eat_or_skip(RPAREN, Sync_Stmt);
StatementNode *if_stmt = Stmt();
StatementNode *else_stmt = Else();
return new IfNode(expr, if_stmt, else_stmt, line);
} else if (lookahead == WHILE) {
eat_token();
eat_or_skip(LPAREN, Sync_Stmt);
ExpNode *expr = ExprAttribution();
eat_or_skip(RPAREN, Sync_Stmt);
return new WhileNode(expr, Stmt(), line);
} else if (lookahead == SWITCH) {
eat_token();
eat_or_skip(LPAREN, Sync_Stmt);
ExpNode *expr = ExprAttribution();
eat_or_skip(RPAREN, Sync_Stmt);
eat_or_skip(LBRACE, Sync_Stmt);
CaseBlockNode *case_block = CaseBlock();
eat_or_skip(RBRACE, Sync_Stmt);
return new SwitchNode(expr, case_block, line);
} else if (lookahead == BREAK) {
eat_token();
eat_or_skip(SEMICOLON, Sync_Stmt);
return new BreakNode(line);
} else if (lookahead == PRINT) {
eat_token();
eat_or_skip(LPAREN, Sync_Stmt);
ExpListNode *list = ExprList();
eat_or_skip(RPAREN, Sync_Stmt);
eat_or_skip(SEMICOLON, Sync_Stmt);
return new PrintlnNode(list, line);
} else if (lookahead == READLN) {
eat_token();
eat_or_skip(LPAREN, Sync_Stmt);
ExpNode *expr = ExprAttribution();
eat_or_skip(RPAREN, Sync_Stmt);
eat_or_skip(SEMICOLON, Sync_Stmt);
return new ReadNode(expr, line);
} else if (lookahead == RETURN) {
eat_token();
ExpNode *expr = ExprAttribution();
eat_or_skip(SEMICOLON, Sync_Stmt);
return new ReturnNode(expr, line);
} else if (lookahead == THROW) {
eat_token();
eat_or_skip(SEMICOLON, Sync_Stmt);
return new ThrowNode(line);
} else if (lookahead == LBRACE) {
eat_token();
StatementListNode *list = StmtList();
eat_or_skip(RBRACE, Sync_Stmt);
return list;
} else if (lookahead == TRY) {
eat_token();
StatementNode *try_stmt = Stmt();
eat_or_skip(CATCH, Sync_Stmt);
eat_or_skip(LPAREN, Sync_Stmt);
eat_or_skip(PERIOD, Sync_Stmt);
eat_or_skip(PERIOD, Sync_Stmt);
eat_or_skip(PERIOD, Sync_Stmt);
eat_or_skip(RPAREN, Sync_Stmt);
return new TryNode(try_stmt, Stmt(), line);
} else if (contains_lookahead(First_ExprAttribution)) {
ExpNode *expr = ExprAttribution();
eat_or_skip(SEMICOLON, Sync_Stmt);
return expr;
} else {
synchronize(ERROR_STATEMENT_EXPECTED, Sync_Stmt);
}
return NULL;
}
StatementNode *Else() {
// printf("\nElse");
if (lookahead == ELSE) {
eat_token();
return Stmt();
}
///else epsilon
return NULL;
}
CaseBlockNode *CaseBlock() {
// printf("\nCaseBlock");
int line = get_line();
if (lookahead == CASE) {
eat_token();
const char *aux = eat_or_skip(INTEGER, Sync_CaseBlock);
IntegerNode *integer = new IntegerNode(aux, line);
eat_or_skip(COLON, Sync_CaseBlock);
return CaseBlockAux(integer);
} else
synchronize(ERROR_CASE_EXPECTED, Sync_CaseBlock);
return NULL;
}
CaseBlockNode *CaseBlockAux(IntegerNode *integer) {
// printf("\nCaseBlockAux");
int line = get_line();
if (contains_lookahead(First_StmtList))
return new CaseBlockNode(integer, StmtList(), CaseBlock(), line);
else if (contains_lookahead(First_CaseBlock))
return new CaseBlockNode(integer, NULL, CaseBlock(), line);
///else epsilon
return NULL;
}
ExpListNode *ExprList() {
// printf("\nExprList");
int line = get_line();
if (contains_lookahead(First_ExprAttribution)) {
return new ExpListNode(ExprAttribution(), ExprListTail(), line);
}
///else epsilon
return NULL;
}
ExpListNode *ExprListTail() {
// printf("\nExprListTail");
if (lookahead == COMMA) {
eat_token();
return ExprList();
}
///else epsilon
return NULL;
}
ExpNode *ExprAttribution() {
// printf("\nExprAttribution");
if (contains_lookahead(First_ExprAlternative))
return ExprAttributionAux(ExprAlternative());
else
synchronize(ERROR_EXPRESSION_EXPECTED, Sync_ExprAttribution);
return NULL;
}
ExpNode *ExprAttributionAux(ExpNode *expr) {
// printf("\nExprAttributionAux");
int line = get_line();
if (lookahead == ASSIGN) {
eat_token();
return new AssignNode(expr, ExprAttribution(), line);
}
///else epsilon
return expr;
}
ExpNode *ExprAlternative() {
// printf("\nExprAlternative");
if (contains_lookahead(First_ExprAnd))
return ExprAlternativeAux(ExprAnd());
else
synchronize(ERROR_EXPRESSION_EXPECTED, Sync_ExprAlternative);
return NULL;
}
ExpNode *ExprAlternativeAux(ExpNode *expr) {
// printf("\nExprAlternativeAux");
int line = get_line();
if (lookahead == ALTERNATIVE) {
eat_token();
return new BooleanOpNode(ALTERNATIVE, expr, ExprAlternative(), line);
}
///else epsilon
return expr;
}
ExpNode *ExprAnd() {
// printf("\nExprAnd");
if (contains_lookahead(First_ExprEquality))
return ExprAndAux(ExprEquality());
else
synchronize(ERROR_EXPRESSION_EXPECTED, Sync_ExprAnd);
return NULL;
}
ExpNode *ExprAndAux(ExpNode *expr) {
// printf("\nExprAndAux");
int line = get_line();
if (lookahead == AND) {
eat_token();
return new BooleanOpNode(AND, expr, ExprAnd(), line);
}
return expr;
}
ExpNode *ExprEquality() {
// printf("\nExprEquality");
if (contains_lookahead(First_ExprRelational))
return ExprEqualityAux(ExprRelational());
else
synchronize(ERROR_EXPRESSION_EXPECTED, Sync_ExprEquality);
return NULL;
}
ExpNode *ExprEqualityAux(ExpNode *expr) {
// printf("\nExprEqualityAux");
int line = get_line();
if (lookahead == EQUAL) {
eat_token();
return new RelationalOpNode(EQUAL, expr, ExprEquality(), line);
} else if (lookahead == NOTEQUAL) {
eat_token();
return new RelationalOpNode(NOTEQUAL, expr, ExprEquality(), line);
}
return expr;
}
ExpNode *ExprRelational() {
// printf("\nExprRelational");
if (contains_lookahead(First_ExprAdd))
return ExprRelationalAux(ExprAdd());
else
synchronize(ERROR_EXPRESSION_EXPECTED, Sync_ExprRelational);
return NULL;
}
ExpNode *ExprRelationalAux(ExpNode *expr) {
// printf("\nExprRelationalAux");
int line = get_line();
if (lookahead == LTE) {
eat_token();
return new RelationalOpNode(LTE, expr, ExprRelational(), line);
} else if (lookahead == GTE) {
eat_token();
return new RelationalOpNode(GTE, expr, ExprRelational(), line);
} else if (lookahead == LT) {
eat_token();
return new RelationalOpNode(LT, expr, ExprRelational(), line);
} else if (lookahead == GT) {
eat_token();
return new RelationalOpNode(GT, expr, ExprRelational(), line);
}
return expr;
}
ExpNode *ExprAdd() {
// printf("\nExprAdd");
if (contains_lookahead(First_ExprMult))
return ExprAddAux(ExprMult());
else
synchronize(ERROR_EXPRESSION_EXPECTED, Sync_ExprAdd);
return NULL;
}
ExpNode *ExprAddAux(ExpNode *expr) {
// printf("\nExprAddAux");
int line = get_line();
if (lookahead == PLUS) {
eat_token();
return new AdditionOpNode(PLUS, expr, ExprAdd(), line);
} else if (lookahead == MINUS) {
eat_token();
return new AdditionOpNode(MINUS, expr, ExprAdd(), line);
} else if (lookahead == ALTERNATIVE_BIT) {
eat_token();
return new BitwiseOpNode(ALTERNATIVE_BIT, expr, ExprAdd(), line);
}
return expr;
}
ExpNode *ExprMult() {
// printf("\nExprMult");
if (contains_lookahead(First_ExprUnary))
return ExprMultAux(ExprUnary());
else
synchronize(ERROR_EXPRESSION_EXPECTED, Sync_ExprMult);
return NULL;
}
ExpNode *ExprMultAux(ExpNode *expr) {
// printf("\nExprMultAux");
int line = get_line();
if (lookahead == MULT) {
eat_token();
return new MultiplicationOpNode(MULT, expr, ExprMult(), line);
} else if (lookahead == DIV) {
eat_token();
return new MultiplicationOpNode(DIV, expr, ExprMult(), line);
} else if (lookahead == MOD) {
eat_token();
return new MultiplicationOpNode(MOD, expr, ExprMult(), line);
} else if (lookahead == AND_BIT) {
eat_token();
return new BitwiseOpNode(AND_BIT, expr, ExprMult(), line);
}
return expr;
}
ExpNode *ExprUnary() {
// printf("\nExprUnary");
int line = get_line();
if (lookahead == MINUS) {
eat_token();
return new SignNode(ExprUnary(), line);
} else if (lookahead == BANG) {
eat_token();
return new NotNode(ExprUnary(), line);
} else if (lookahead == PLUS) {
eat_token();
return ExprUnary();
} else if (lookahead == MULT) {
eat_token();
return new PointerValueNode(ExprUnary(), line);
} else if (lookahead == AND_BIT) {
eat_token();
return new AddressValueNode(ExprUnary(), line);
} else if (contains_lookahead(First_Primary))
return Primary();
else
synchronize(ERROR_UNEXPECTED_TOKEN, Sync_ExprUnary);
return NULL;
}
ExpNode *Primary() {
// printf("\nPrimary");
int line = get_line();
if (lookahead == ID) {
IdentifierNode *id = new IdentifierNode(get_lexeme(), line);
eat_token();
return new PrimaryNode(id, PrimaryFat(id), line);
} else if (lookahead == INTEGER) {
IntegerNode *integer = new IntegerNode(get_lexeme(), line);
eat_token();
return new PrimaryNode(integer, FieldAccess(), line);
} else if (lookahead == REAL) {
RealNode *real = new RealNode(get_lexeme(), line);
eat_token();
return new PrimaryNode(real, FieldAccess(), line);
} else if (lookahead == CHARACTER) {
CharacterNode *character = new CharacterNode(get_lexeme(), line);
eat_token();
return new PrimaryNode(character, FieldAccess(), line);
} else if (lookahead == LITERAL) {
LiteralNode *literal = new LiteralNode(get_lexeme(), line);
eat_token();
return new PrimaryNode(literal, FieldAccess(), line);
} else if (lookahead == TRUE) {
eat_token();
return new PrimaryNode(new TrueNode(line), FieldAccess(), line);
} else if (lookahead == FALSE) {
eat_token();
return new PrimaryNode(new FalseNode(line), FieldAccess(), line);
} else if (lookahead == THIS) {
eat_token();
return new PrimaryNode(new ThisNode(line), FieldAccess(), line);
} else if (lookahead == LPAREN) {
eat_token();
ExpNode *expr = ExprAttribution();
eat_or_skip(RPAREN, Sync_Primary);
return new PrimaryNode(expr, FieldAccess(), line);
} else if (lookahead == NEW) {
eat_token();
const char *aux = eat_or_skip(ID, Sync_Expr);
IdentifierNode *id = new IdentifierNode(aux, line);
eat_or_skip(LPAREN, Sync_Expr);
ExpListNode *list = ExprList();
eat_or_skip(RPAREN, Sync_Expr);
return new PrimaryNode(new NewNode(id, list, line), FieldAccess(), line);
} else
synchronize(ERROR_UNEXPECTED_TOKEN, Sync_Primary);
return NULL;
}
ExpNode *PrimaryFat(IdentifierNode *id) {
// printf("\nPrimaryFat");
if (lookahead == LPAREN) {
int line = get_line();
eat_token();
ExpListNode *exp_list = ExprList();
eat_or_skip(RPAREN, Sync_PrimaryFat);
return new FunctionCallNode(id, exp_list, FieldAccess(), line);
} else
return FieldAccess();
}
ExpNode *FieldAccess() {
// printf("\nFieldAccess");
int line = get_line();
if (lookahead == PERIOD) {
eat_token();
if (contains_lookahead(First_Primary))
return new FieldAccessNode(Primary(), line);
} else if (lookahead == POINTER) {
eat_token();
if (contains_lookahead(First_Primary))
return new PointerAccessNode(Primary(), line);
} else if (lookahead == LBRACKET) {
eat_token();
ExpNode *index_expr = ExprAttribution();
eat_or_skip(RBRACKET, Sync_FieldAccess);
return new ArrayAccessNode(index_expr, FieldAccess(), line);
}
///else epsilon
return NULL;
}
/****************************************************************************************
******************************** PRODUCTIONS END ****************************************
****************************************************************************************/