-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathraft_parser.yy
More file actions
2342 lines (2165 loc) · 73.8 KB
/
raft_parser.yy
File metadata and controls
2342 lines (2165 loc) · 73.8 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
%skeleton "lalr1.cc"
%require "3.0"
%debug
%defines
%define api.namespace {Raft}
%define parser_class_name {Parser}
/* pre-declare classes that are needed for the parser here */
%code requires{
namespace Raft {
class Driver;
class Scanner;
class Data;
}
namespace Node {
class NodeAbstract;
class BooleanType;
class Source;
class Filename;
class Initializer;
class Type;
class ObjectType;
class Int8Type;
class Int16Type;
class Int32Type;
class Int64Type;
class UInt8Type;
class UInt16Type;
class UInt32Type;
class UInt64Type;
class Float32Type;
class Float64Type;
class Float96Type;
class StringType;
class AutomaticType;
class VoidType;
class ValueBase;
class Bang;
class Tilde;
class Allocation;
class Returns;
class UnaryMinus;
class UnaryPlus;
class Super;
class Nill;
class This;
class QualifiedName;
class DelayedName;
class StreamPropertyList;
class VariableStreams;
class Referencing;
class StreamReferencing;
class VariableReferencing;
class MethodReferencing;
class ArgumentList;
class StreamArgumentList;
class MethodArgumentList;
class ClassDeclaration;
class Generic;
class GenericTypeParam;
class GenericClassParam;
class GenericTypeMultiple;
class GenericList;
class Inherit;
class Interface;
class Body;
class EmptyBody;
class Visibility;
class Public;
class Private;
class Protected;
class Access;
class ArrayAccess;
class FieldAccess;
class Parameter;
class PlaceholderParameter;
class FieldVarDecl;
class StorageModifier;
class NoStorageModifier;
class Constant;
class Static;
class NonAtomic;
class Atomic;
class Synchronized;
class Unsynchronized;
class ClassInitializer;
class EmptyClassInitializer;
class ConstructorDeclaration;
class StreamingMethodDeclaration;
class Converge;
class Fork;
class MethodDeclaration;
class EmptyTypeModifier;
class MethodInherit;
class MethodImplements;
class MethodOverrides;
class MethodNoInherit;
class ClassInherit;
class ClassExtends;
class ClassNoInherit;
class ClassImplements;
class NoParameter;
class Block;
class EmptyBlock;
class StreamEdges;
class StreamInput;
class NoStreamInput;
class StreamOutput;
class NoStreamOutput;
class ParameterList;
class NoParameterList;
class SimpleParameter;
class ArrayParameter;
class SizedArrayParameter;
class NoTypeModifier;
class VariableDeclaration;
class NoArgumentList;
class InstantiationModifier;
class System;
class Final;
class Abstract;
class NoInstantiationModifier;
class DynamicArray;
class NoSizeParameter;
class NoDynamicArray;
class GenericInstantiationList;
class NoGenericInstantiation;
class GenericInstantiation;
class Assignment;
class Equals;
class ArraySize;
class Increment;
class Decrement;
class AssPlus;
class AssMinus;
class Plus;
class Minus;
class CondOp;
class LOROp;
class LANDOp;
class OrOp;
class HatOp;
class AndOp;
class EqualityOp;
class EqualOp;
class NotEqualOp;
class GreaterThanOp;
class LessThanOp;
class LessEqualOp;
class GreaterEqualOp;
class MultOp;
class DivOp;
class ModOp;
class LeftShiftOp;
class RightShiftOp;
class TypeCastExpression;
class Free;
class ModOp;
class AllOthersInArray;
class ArrayInitialization;
class BoolArrayInitialization;
class NumArrayInitialization;
class StrArrayInitialization;
class ArraySlice;
class EmptyStatement;
class Statement;
class IfStatement;
class WhileStatement;
class ForStatement;
class MapStatement;
class LocalVarDecl;
class MethodReturns;
class NoMethodModifier;
class Streams;
}
}
/* params for yylex */
%lex-param { Scanner &scanner }
%parse-param { Scanner &scanner }
%lex-param { Driver &driver }
%parse-param { Driver &driver }
%lex-param { Data &data }
%parse-param { Data &data }
%code{
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cstdint>
#include <cinttypes>
#include <cstring>
#include <typeinfo>
/* include for all driver functions */
#include "driver.hpp"
#include "data.hpp"
#include "common.hpp"
#include "cpp_output_handler.hpp"
/* nodes */
#include "NodeAbstract.hpp"
#include "Source.hpp"
#include "Declaration.hpp"
#include "FieldVarDecl.hpp"
#include "Filename.hpp"
#include "BooleanType.hpp"
#include "Initializer.hpp"
#include "Value.tcc"
#include "ValueBase.hpp"
#include "Int8Type.hpp"
#include "Int16Type.hpp"
#include "Int32Type.hpp"
#include "Int64Type.hpp"
#include "UInt8Type.hpp"
#include "UInt16Type.hpp"
#include "UInt32Type.hpp"
#include "UInt64Type.hpp"
#include "Float32Type.hpp"
#include "Float64Type.hpp"
#include "Float96Type.hpp"
#include "StringType.hpp"
#include "ObjectType.hpp"
#include "Type.hpp"
#include "AutomaticType.hpp"
#include "VoidType.hpp"
#include "Bang.hpp"
#include "Tilde.hpp"
#include "Allocation.hpp"
#include "New.hpp"
#include "Returns.hpp"
#include "UnaryPlus.hpp"
#include "UnaryMinus.hpp"
#include "Super.hpp"
#include "Nill.hpp"
#include "This.hpp"
#include "QualifiedName.hpp"
#include "DelayedName.hpp"
#include "StreamPropertyList.hpp"
#include "VariableStreams.hpp"
#include "Referencing.hpp"
#include "VariableReferencing.hpp"
#include "MethodReferencing.hpp"
#include "StreamReferencing.hpp"
#include "ArgumentList.hpp"
#include "StreamArgumentList.hpp"
#include "MethodArgumentList.hpp"
#include "ClassDeclaration.hpp"
#include "Generic.hpp"
#include "GenericTypeParam.hpp"
#include "GenericClassParam.hpp"
#include "GenericTypeMultiple.hpp"
#include "GenericList.hpp"
#include "Inherit.hpp"
#include "Interface.hpp"
#include "Body.hpp"
#include "EmptyBody.hpp"
#include "Visibility.hpp"
#include "Public.hpp"
#include "Private.hpp"
#include "Protected.hpp"
#include "Access.hpp"
#include "FieldAccess.hpp"
#include "ArrayAccess.hpp"
#include "Parameter.hpp"
#include "PlaceholderParameter.hpp"
#include "StorageModifier.hpp"
#include "NoStorageModifier.hpp"
#include "Constant.hpp"
#include "NonAtomic.hpp"
#include "Atomic.hpp"
#include "Synchronized.hpp"
#include "Unsynchronized.hpp"
#include "Static.hpp"
#include "ClassInitializer.hpp"
#include "EmptyClassInitializer.hpp"
#include "ConstructorDeclaration.hpp"
#include "StreamingMethodDeclaration.hpp"
#include "Converge.hpp"
#include "Fork.hpp"
#include "MethodDeclaration.hpp"
#include "EmptyTypeModifier.hpp"
#include "ClassInherit.hpp"
#include "ClassNoInherit.hpp"
#include "ClassExtends.hpp"
#include "ClassImplements.hpp"
#include "MethodInherit.hpp"
#include "MethodNoInherit.hpp"
#include "MethodOverrides.hpp"
#include "MethodImplements.hpp"
#include "NoParameter.hpp"
#include "Block.hpp"
#include "EmptyBlock.hpp"
#include "StreamEdges.hpp"
#include "StreamInput.hpp"
#include "StreamOutput.hpp"
#include "NoStreamInput.hpp"
#include "NoStreamOutput.hpp"
#include "ParameterList.hpp"
#include "NoParameterList.hpp"
#include "SimpleParameter.hpp"
#include "ArrayParameter.hpp"
#include "SizedArrayParameter.hpp"
#include "VariableDeclaration.hpp"
#include "NoTypeModifier.hpp"
#include "NoArgumentList.hpp"
#include "NoInstantiationModifier.hpp"
#include "System.hpp"
#include "Final.hpp"
#include "Abstract.hpp"
#include "InstantiationModifier.hpp"
#include "DynamicArray.hpp"
#include "NoSizeParameter.hpp"
#include "NoDynamicArray.hpp"
#include "GenericInstantiationList.hpp"
#include "NoGenericInstantiation.hpp"
#include "GenericInstantiation.hpp"
#include "Assignment.hpp"
#include "Equals.hpp"
#include "ArraySize.hpp"
#include "Increment.hpp"
#include "Decrement.hpp"
#include "AssPlus.hpp"
#include "AssMinus.hpp"
#include "Plus.hpp"
#include "Minus.hpp"
#include "CondOp.hpp"
#include "LOROp.hpp"
#include "LANDOp.hpp"
#include "OrOp.hpp"
#include "HatOp.hpp"
#include "AndOp.hpp"
#include "EqualityOp.hpp"
#include "EqualOp.hpp"
#include "NotEqualOp.hpp"
#include "GreaterThanOp.hpp"
#include "LessThanOp.hpp"
#include "LessEqualOp.hpp"
#include "GreaterEqualOp.hpp"
#include "MultOp.hpp"
#include "DivOp.hpp"
#include "ModOp.hpp"
#include "TypeCastExpression.hpp"
#include "LeftShiftOp.hpp"
#include "RightShiftOp.hpp"
#include "Free.hpp"
#include "ModOp.hpp"
#include "ArrayInitialization.hpp"
#include "BoolArrayInitialization.hpp"
#include "NumArrayInitialization.hpp"
#include "StrArrayInitialization.hpp"
#include "AllOthersInArray.hpp"
#include "ArraySlice.hpp"
#include "EmptyStatement.hpp"
#include "Statement.hpp"
#include "IfStatement.hpp"
#include "WhileStatement.hpp"
#include "ForStatement.hpp"
#include "MapStatement.hpp"
#include "LocalVarDecl.hpp"
#include "MethodReturns.hpp"
#include "NoMethodModifier.hpp"
#include "Streams.hpp"
/* define proper yylex */
static int yylex(Raft::Parser::semantic_type *yylval,
Raft::Scanner &scanner,
Raft::Driver &driver,
Raft::Data &data );
using namespace Node;
}
/* token types */
%union{
semantic_type() : sval( nullptr )
{
}
/* mostly basic types */
std::string *sval;
bool bval;
uintmax_t uint_val;
long double dval;
char cval;
/* begin node types */
Node::NodeAbstract *node;
Node::ValueBase *valnode;
Node::Type *typenode;
}
%token END 0 "end of file"
%token AT
%token DOLLAR
%token LBRACE
%token RBRACE
%token LBRACKET
%token RBRACKET
%token LPAREN
%token RPAREN
%token LCARROT
%token RCARROT
%token DLBRACKET
%token DRBRACKET
%token DLCARROT
%token DRCARROT
%token COLON
%token SEMI
%token AUTOGEN
%token AUTO
%token FINAL
%token CLASS
%token SYSTEM
%token ABSTRACT
%token INTERFACE
%token OVERRIDES
%token IMPLEMENTS
%token EXTENDS
%token STREAM
%token ATPUBLIC
%token ATPRIVATE
%token ATPROTECTED
%token SIGNAL
%token SENDSIGNAL
%token FUNK
%token EL
%token RETURN
%token VOID
%token THIS
%token SUPER
%token NEW
%token FOR
%token FOREACH
%token WHILE
%token IF
%token ELSE
%token NILL
%token CONST
%token STATIC
%token ATOMIC
%token NONATOMIC
%token STRUCT
%token VAR
%token INCREMENT
%token DECREMENT
%token QUESTION
%token FORWARDSLASH
%token MINUS
%token PLUS
%token OP_EQ
%token OP_NE
%token OP_LE
%token OP_GE
%token BANG
%token PERCENT
%token OP_LOR
%token OR
%token OP_LAND
%token AND
%token ASS_MINUS
%token ASS_PLUS
%token EQUALS
%token ASTERICK
%token TILDE
%token PERIOD
%token HAT
%token THREEDOTS
%token COMMA
%token BOOLEAN
%token CHAR
%token INT8T
%token INT16T
%token INT32T
%token INT64T
%token UINT8T
%token UINT16T
%token UINT32T
%token UINT64T
%token FLOAT32
%token FLOAT64
%token FLOAT96
%token POUND
%token STRING
%token SYNCHRONIZED
%token UNSYNCHRONIZED
%token <bval> TRUE
%token <bval> FALSE
%token <sval> STR_TOKEN
%token <uint_val> INT_TOKEN
%token <dval> FLOAT_TOKEN
%token <sval> IDENTIFIER
/* begin types */
%type <node> TypeDeclaration
%type <node> T
%type <node> Filename
%type <node> InterfaceDeclaration
%type <node> ClassDeclaration
%type <node> Generic
%type <node> GenericList
%type <node> GenericListA
%type <node> Inherit
%type <node> InstantModifier
%type <node> Body
%type <typenode> Type
%type <node> TypeModifier
%type <node> Initializer
%type <node> Visibility
%type <node> FieldDeclaration
%type <node> FieldVariableDeclaration
%type <node> MethodDeclaration
%type <node> ConstructorDeclaration
%type <node> MultiObjectInit
%type <node> StorageModifier
%type <node> MethodBody
%type <node> MethodDeclarator
%type <node> ParameterList
%type <node> Parameter
%type <node> DeclaratorName
%type <node> LocalVariableDeclarationsAndStatements
%type <node> LocalVariableDeclarationOrStatement
%type <node> Statement
%type <node> EmptyStatement
%type <node> ExpressionStatement
%type <node> Expression
%type <node> SelectionStatementInit
%type <node> IterationStatement
%type <node> ForIterationStatement
%type <node> BasicFor
%type <node> ForStatement
%type <node> MapExpression
%type <node> InitFor
%type <node> ReturnStatement
%type <node> MultiBoolInit
%type <node> BoolInitializer
%type <node> ObjectInitializer
%type <node> MultiNumberInit
%type <node> NumberInitializer
%type <node> MultiStringInit
%type <node> StrInitializer
%type <typenode> AutoType
%type <typenode> BoolType
%type <typenode> IntType
%type <typenode> FloatType
%type <typenode> StringType
%type <typenode> ObjectType
%type <node> GenericInstantiationList
%type <node> AllowedGenericInstTypes
%type <node> ArraySize
%type <node> AssignmentExpression
%type <node> AssignmentOperator
%type <node> ConditionalExpression
%type <node> ConditionalOrExpression
%type <node> ConditionalAndExpression
%type <node> InclusiveOrExpression
%type <node> ExclusiveOrExpression
%type <node> AndExpression
%type <node> EqualityExpression
%type <node> RelationalExpression
%type <node> ShiftExpression
%type <node> AdditiveExpression
%type <node> MultiplicativeExpression
%type <node> CastExpression
%type <node> UnaryExpression
%type <node> PostfixExpression
%type <node> PrimaryExpression
%type <node> NotJustName
%type <node> ComplexPrimary
%type <node> ComplexPrimaryNoParenthesis
%type <node> Placeholder
%type <node> ArrayAccess
%type <node> FieldAccess
%type <node> MethodCall
%type <node> QualifiedName
%type <node> SpecialName
%type <node> ArgumentList
%type <node> ArithmeticUnaryOperator
%type <node> LogicalUnaryExpression
%type <node> LogicalUnaryOperator
%type <valnode> Literal
%type <valnode> Number
%type <valnode> Boolean
%type <node> Block
%type <node> DelayedName
%type <node> StreamCall
%type <node> StorageModifierI
%type <node> GenericInstantiation
%type <node> SelectiveArrayInitializerNum
%type <node> SelectiveArrayInitializerBool
%type <node> SelectiveArrayInitializerStr
%type <node> MultipleArrayInitBool
%type <node> MultipleArrayInitNum
%type <node> MultipleArrayInitStr
%type <node> ArraySlice
%type <node> ArrayAccessOptions
%type <node> Slice
%type <node> GenericRestrictions
%type <node> ClassList
%type <node> MethodModifiers
%type <node> MethodModifier
%type <node> MethodInherits
%type <node> MethodReturns
%type <node> AllocationExpression
%token RETURNTYPE
%token FUNC
%%
CompilationUnit : END
| T
{
Node::Source *s( nullptr );
s = new Node::Source();
driver.set_root( s );
s->AdoptChildren( $1 );
}
;
T : Filename
{
$$ = $1;
}
| TypeDeclaration
{
$$ = $1;
}
| T Filename
{
$1->MakeSibling( $2 );
}
| T TypeDeclaration
{
$1->MakeSibling( $2 );
}
| error
{
$$ = new NodeAbstract();
$$->set_name( "Error" );
}
;
/* handle cpp file names for errors */
Filename : POUND INT_TOKEN STR_TOKEN
{
Common::RemoveStringQuotes( *$3 );
data.get_cpp_handler().AddUpdate(
$2 /* line # */,
*$3 /* name */ );
Node::Filename *f( nullptr );
f = new Node::Filename( *$3 );
f->SetOrigin( data );
$$ = f;
/* get rid of allocated string */
delete( $3 );
}
| POUND INT_TOKEN STR_TOKEN INT_TOKEN
{
Common::RemoveStringQuotes( *$3 );
data.get_cpp_handler().AddUpdate(
$2 /* line # */,
*$3 /* name */,
$4 /* flags */ );
Node::Filename *f( nullptr );
f = new Node::Filename( *$3 );
f->SetOrigin( data );
f->set_name( *$3 );
$$ = f;
/* get rid of allocated string */
delete( $3 );
}
;
TypeDeclaration : ClassDeclaration
{
$$ = $1;
}
| InterfaceDeclaration
{
$$ = $1;
}
;
ClassDeclaration : InstantModifier CLASS IDENTIFIER Generic Inherit LBRACE Body RBRACE
{
NodeAbstract *cls( nullptr );
cls = new ClassDeclaration( *$3 );
delete( $3 );
cls->AdoptChildren( $1 );
cls->AdoptChildren( $4 );
cls->AdoptChildren( $5 );
cls->AdoptChildren( $7 );
$$ = cls;
}
| InstantModifier CLASS IDENTIFIER Generic Inherit LBRACE RBRACE
{
NodeAbstract *cls( nullptr );
cls = new ClassDeclaration( *$3 );
delete( $3 );
cls->AdoptChildren( $1 );
cls->AdoptChildren( $4 );
cls->AdoptChildren( $5 );
$$ = cls;
}
;
InstantModifier : FINAL SYSTEM
{
$$ = new Final();
$$->MakeSibling( new System() );
}
| FINAL
{
$$ = new Final();
}
| ABSTRACT
{
$$ = new Abstract();
}
|
{
$$ = new NoInstantiationModifier();
}
;
Generic : LCARROT GenericList RCARROT
{
NodeAbstract *gl = new GenericList();
$$ = gl;
$$->AdoptChildren( $2 );
}
| {
NodeAbstract *gl = new GenericList();
$$ = gl;
}
;
GenericList : GenericListA
{
$$ = $1;
}
| GenericList COMMA GenericListA
{
$1->MakeSibling( $3 );
$$ = $1;
}
;
GenericListA : CLASS IDENTIFIER GenericRestrictions
{
NodeAbstract *cl( nullptr );
cl = new GenericClassParam( *$2 );
delete( $2 );
$$ = cl;
}
| Type IDENTIFIER TypeModifier GenericRestrictions
{
NodeAbstract *cl( nullptr );
cl = new GenericTypeParam( *$2 );
delete( $2 );
cl->AdoptChildren( $1 );
cl->AdoptChildren( $3 );
$$ = cl;
}
;
GenericRestrictions : EXTENDS Type
{
$$ = new NodeAbstract();
$$->AdoptChildren( $2 );
}
| IMPLEMENTS QualifiedName
{
$$ = new NodeAbstract();
$$->AdoptChildren( $2 );
}
| EL LBRACE ClassList RBRACE
{
$$ = new NodeAbstract();
$$->AdoptChildren( $3 );
}
|
{
$$ = new NodeAbstract();
}
;
ClassList : Type
{
$$ = $1;
}
| ClassList COMMA Type
{
$$ = $1;
$$->MakeSibling( $3 );
}
;
Inherit : COLON EXTENDS Type
{
$$ = new ClassExtends( );
$$->AdoptChildren( $3 );
}
| COLON IMPLEMENTS ObjectType
{
$$ = new ClassImplements();
$$->AdoptChildren( $3 );
}
|
{
$$ = new ClassNoInherit();
}
;
InterfaceDeclaration : INTERFACE IDENTIFIER LBRACE Body RBRACE
{
NodeAbstract *interface( nullptr );
interface = new Interface( *$2 );
delete( $2 );
interface->AdoptChildren( $4 );
$$ = interface;
}
| INTERFACE IDENTIFIER LBRACE RBRACE
{
NodeAbstract *interface( nullptr );
interface = new Interface( *$2 );
delete( $2 );
interface->AdoptChildren( new EmptyBody() );
$$ = interface;
}
;
Body : Visibility
{
$$ = $1;
}
| FieldDeclaration
{
$$ = $1;
}
| Body Visibility
{
$1->MakeSibling( $2 );
$$ = $1;
}
| Body FieldDeclaration
{
$1->MakeSibling( $2 );
$$ = $1;
}
;
Visibility : ATPUBLIC
{
$$ = new Public();
}
| ATPROTECTED
{
$$ = new Protected();
}
| ATPRIVATE
{
$$ = new Private();
}
;
FieldDeclaration : FieldVariableDeclaration
{
$$ = $1;
}
| MethodDeclaration
{
$$ = $1;
}
| ConstructorDeclaration
{
$$ = $1;
}
;
FieldVariableDeclaration :
VAR StorageModifier Type Initializer SEMI
{
$$ = new FieldVarDecl();
$$->AdoptChildren( $2 );
$$->AdoptChildren( $3 );
$$->AdoptChildren( $4 );
}
| CONST StorageModifier Type Initializer SEMI
{
//TODO
$$ = new FieldVarDecl();
$$->AdoptChildren( $2 );
$$->AdoptChildren( $3 );
$$->AdoptChildren( $4 );
}
| VAR Type Initializer SEMI
{
$$ = new FieldVarDecl();
$$->AdoptChildren( $2 );
$$->AdoptChildren( $3 );
}
| CONST Type Initializer SEMI
{
$$ = new FieldVarDecl();
$$->AdoptChildren( $2 );
$$->AdoptChildren( $3 );
}
;
StorageModifier : StorageModifierI
{
$$ = $1;
}
| StorageModifier StorageModifierI
{
$1->MakeSibling( $2 );
$$ = $1;
}
;
StorageModifierI : STATIC
{
$$ = new Static();
}
| NONATOMIC
{
$$ = new NonAtomic();
}
| ATOMIC
{
$$ = new Atomic();
}
| SYNCHRONIZED
{
$$ = new Synchronized();
}
| UNSYNCHRONIZED
{
$$ = new Unsynchronized();
}
;
ConstructorDeclaration : MethodDeclarator Block
{
NodeAbstract *cons( nullptr );
cons = new ConstructorDeclaration();
cons->AdoptChildren( $1 );
cons->AdoptChildren( new EmptyClassInitializer() );
cons->AdoptChildren( $2 );
$$ = cons;
}
;
MethodDeclaration : MethodModifiers MethodDeclarator MethodReturns MethodBody
{
$$ = $2;
$$->AdoptChildren( $1 );
$$->AdoptChildren( $3 );
$$->AdoptChildren( $4 );
}
;
MethodReturns : RETURNTYPE LPAREN ParameterList RPAREN
{
$$ = new NodeAbstract( );
}
| RETURNTYPE DLBRACKET ParameterList DRBRACKET
{
$$ = new NodeAbstract( );
}
;
MethodModifiers :
MethodModifier StorageModifier MethodInherits
{
$1->AdoptChildren( $2 );
$1->AdoptChildren( $3 );
$$ = $1;
}
| MethodModifier MethodInherits
{
$1->AdoptChildren( $2 );
$$ = $1;
}
| MethodModifier
{