-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.cup
968 lines (881 loc) · 30.5 KB
/
parser.cup
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
/*
Grammaire attribuée pour construire l'arbre abstrait correspondant au langage Block
*/
package fr.n7.stl.block;
import java_cup.runtime.*;
import fr.n7.stl.block.Lexer;
import java.io.*;
import java.util.*;
// Elements du métamodèle pour la construction de l'arbre abstrait
import fr.n7.stl.block.ast.*;
import fr.n7.stl.block.ast.expression.*;
import fr.n7.stl.block.ast.expression.accessible.*;
import fr.n7.stl.block.ast.expression.allocation.*;
import fr.n7.stl.block.ast.expression.assignable.*;
import fr.n7.stl.block.ast.expression.value.*;
import fr.n7.stl.block.ast.instruction.*;
import fr.n7.stl.block.ast.instruction.declaration.*;
import fr.n7.stl.block.ast.scope.*;
import fr.n7.stl.block.ast.type.*;
import fr.n7.stl.poo.call.*;
import fr.n7.stl.poo.declaration.*;
import fr.n7.stl.block.poo.methode.*;
import fr.n7.stl.poo.definition.*;
import fr.n7.stl.poo.type.*;
import fr.n7.stl.block.ast.type.declaration.*;
import fr.n7.stl.tam.ast.*;
import fr.n7.stl.tam.ast.impl.*;
import fr.n7.stl.util.*;
/* Variables partagées dans les actions de l'analyseur syntaxique. */
parser code {:
protected Lexer lexer;
protected String name;
public String getName() {
return this.name;
}
public Parser(String _name) {
this();
this.name = _name;
}
:}
/* Initialisation de l'analyseur lexical et des variables partagées. */
init with {:
ComplexSymbolFactory f = new ComplexSymbolFactory();
symbolFactory = f;
File file = new File(this.name);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (IOException e) {
e.printStackTrace();
}
lexer = new Lexer(f,fis);
:};
/* Expression qui permet de progresser dans l'analyse lexicale. */
scan with {: return lexer.next_token(); :};
/* Terminaux qui seront transmis par l'analyseur lexical. */
terminal UL_Point_Virgule, UL_Virgule, UL_Point, UL_Deux_Points, UL_Point_Interrogation, UL_Point_Exclamation;
terminal UL_Egal, UL_Double_Plus, UL_Double_Moins, UL_Double_Plus_Prefixe, UL_Double_Moins_Prefixe;
terminal UL_Plus, UL_Moins, UL_Moins_Unaire, UL_Asterisque, UL_Oblique, UL_Pour_Cent;
terminal UL_Esperluette, UL_Double_Barre, UL_Double_Esperluette;
terminal UL_Parenthese_Ouvrante, UL_Parenthese_Fermante;
terminal UL_Comme, UL_Premier, UL_Second;
terminal UL_Accolade_Ouvrante, UL_Accolade_Fermante;
terminal UL_Crochet_Ouvrant, UL_Crochet_Fermant;
terminal UL_Inferieur, UL_Superieur;
terminal UL_Inferieur_Egal, UL_Superieur_Egal;
terminal UL_Double_Egal, UL_Exclamation_Egal;
terminal UL_Si, UL_Sinon, UL_Tant_Que, UL_Nouveau, UL_Afficher, UL_Retour;
terminal UL_Definition_Constante, UL_Definition_Type, UL_Enregistrement, UL_Enumeration;
terminal UL_Type_Booleen, UL_Type_Caractere, UL_Type_Chaine, UL_Type_Entier, UL_Type_Flottant, UL_Type_Vide;
terminal UL_Interface, UL_Extends, UL_Final, UL_Abstract, UL_Public, UL_Private, UL_Static, UL_Class, UL_Implements, UL_Protected, UL_This,UL_SUPER, UL_Construct, UL_ARGS;
terminal String UL_Identificateur, UL_Identificateur_Type, UL_Chaine, UL_Caractere;
terminal String UL_Nombre_Entier, UL_Nombre_Flottant, UL_Nul, UL_Vrai, UL_Faux; // Valeur transmise par l'analyseur lexical
/* Non terminaux avec type renvoyé par actions sémantiques (RESULT = ...) */
non terminal Block Program;
non terminal Block Bloc;
non terminal List<Instruction> Instructions;
non terminal Instruction Instruction;
non terminal Instruction Declaration;
non terminal List<Expression> Expressions;
non terminal List<FieldDeclaration> Champs;
non terminal FieldDeclaration Champ;
non terminal List<LabelDeclaration> Etiquettes;
non terminal LabelDeclaration Etiquette;
non terminal List<ParameterDeclaration> Parameters;
non terminal Pair<String,PartialType> Identifiant;
non terminal Type Type, Atomique;
non terminal Expression Expression;
non terminal AssignableExpression Affectable;
non terminal List<ContainerDeclaration> Programs;
non terminal List<ContainerDeclaration> Containers;
non terminal ContainerDeclaration Container;
non terminal ClasseDeclaration Classe;
non terminal InterfaceDeclaration Interface;
non terminal Extension Extension;
non terminal List<Instanciation> Implementations;
non terminal Integer FinalOrAbstract;
non terminal PooDeclaration PooDeclaration;
non terminal List<GenericTypeDeclaration> GenDeclarations;
non terminal GenericTypeDeclaration GenDeclaration;
non terminal List<Instanciation> ExtendsGenDeclaration;
non terminal List<Instanciation> ExtensionsI;
non terminal Instanciation Instanciation;
non terminal List<Instanciation> Instanciations;
non terminal List<MethodeSignature> Entetes;
non terminal MethodeSignature Entete;
non terminal List<Definition> Definitions;
non terminal Definition Definition;
non terminal Methode Methode;
non terminal Attribut Attribut;
non terminal Attribut AttributFinal;
non terminal Boolean PublicOrPrivate;
non terminal Boolean Static;
/* Associativité et Priorité relative des opérateurs (du moins prioritaire au plus prioritaire) */
/* Opérateur le moins prioritiaire */
// precedence nonassoc UL_Parenthese_Fermante; // Résolution du conflit décaler/réduire sur conversion de type
precedence right UL_Egal;
precedence nonassoc UL_Point_Interrogation, UL_Deux_Points;
precedence left UL_Double_Barre;
precedence left UL_Double_Esperluette;
precedence nonassoc UL_Double_Egal, UL_Exclamation_Egal;
precedence nonassoc UL_Inferieur, UL_Inferieur_Egal, UL_Superieur, UL_Superieur_Egal;
precedence left UL_Plus, UL_Moins;
precedence left UL_Asterisque, UL_Oblique, UL_Pour_Cent;
precedence right UL_Nouveau;
precedence left UL_Premier, UL_Second;
precedence left UL_Double_Plus_Prefixe, UL_Double_Moins_Prefixe, UL_Moins_Unaire, UL_Esperluette, UL_Point_Exclamation;
precedence nonassoc UL_Double_Plus, UL_Double_Moins;
precedence left UL_Crochet_Ouvrant, UL_Point, UL_Parenthese_Ouvrante;
/* Opérateur le plus prioritaire */
/* Règles de grammaire attribuée pour la construction de l'arbre abstrait */
/* Program et Bloc sont des non terminaux */
/* UL_Identificateur est un terminal (Unité lexicale) */
/* bloc est la variable utilisable dans l'action sémantique qui contient la valeur renvoyé par l'analyse du Bloc */
Program ::= Containers : containers
{:
// System.out.println( "Block named : " + nom );
// System.out.println( bloc );
SymbolTable tds = new SymbolTable();
boolean resolveResult = true;
for(ContainerDeclaration cd : containers){
if (cd instanceof ClasseDeclaration){
ClasseDeclaration cld = (ClasseDeclaration) cd;
resolveResult = cld.resolvePre(tds) && resolveResult;
}else{
InterfaceDeclaration id = (InterfaceDeclaration) cd;
resolveResult = id.resolvePre(tds) && resolveResult;
}
}
for(ContainerDeclaration cd : containers){
if (cd instanceof ClasseDeclaration){
ClasseDeclaration cld = (ClasseDeclaration) cd;
resolveResult = cld.completeResolve(tds) && resolveResult;
}else{
InterfaceDeclaration id = (InterfaceDeclaration) cd;
resolveResult = id.completeResolve(tds) && resolveResult;
}
}
if(!resolveResult)
System.out.println("Resolve not working");
else {
System.out.println("Resolve Worked");
boolean typeResult = true;
for(ContainerDeclaration cd : containers){
if (cd instanceof ClasseDeclaration){
ClasseDeclaration cld = (ClasseDeclaration) cd;
typeResult = cld.checkType() && typeResult;
}else{
InterfaceDeclaration id = (InterfaceDeclaration) cd;
typeResult = id.checkType() && typeResult;
}
}
if(!typeResult)
System.out.println("CheckType failed");
else{
System.out.println("CheckType Worked");
int size = 0 ;
for(ContainerDeclaration cd : containers){
if(cd instanceof ClasseDeclaration){
ClasseDeclaration cld = (ClasseDeclaration) cd;
size += cld.allocateMemory(Register.CB,size);
}
}
TAMFactoryImpl factory = new TAMFactoryImpl();
Fragment code = factory.createFragment();
for(ContainerDeclaration cd : containers){
if (cd instanceof ClasseDeclaration)
{
// Fragment codeOfclass = cld.getCode(factory);
// code.append(codeOfclass);
ClasseDeclaration cld = (ClasseDeclaration) cd;
code.append(cld.getCode(factory));
}
else{
// InterfaceDeclaration id = (InterfaceDeclaration) cd;
// typeResult = id.getCode(factory);
}
}
for(ContainerDeclaration cd : containers){
if (cd instanceof ClasseDeclaration)
{
ClasseDeclaration cld = (ClasseDeclaration) cd;
Methode main = cld.getMain();
// if(main != null)
// {
// main.allocateMemory(Register.SB,size);
// code.append(main.getCode(factory));
// }
}
}
code.add(factory.createHalt());
File file = new File(parser.getName() + "_tam");
PrintStream printer = null;
try {
printer = new PrintStream( new FileOutputStream(file) );
printer.println( code );
} catch (IOException e) {
e.printStackTrace();
}
}
}
:}
;
Containers ::= Containers : containers Container : container
{:
containers.add(container);
RESULT = containers;
:}
|{:
List<ContainerDeclaration> newContainer = new LinkedList<ContainerDeclaration>();
RESULT = newContainer;
:}
;
Container ::= Interface : interf
{:
RESULT = interf;
:}
| Classe : classe
{:
RESULT = classe;
:}
;
Interface ::= UL_Interface PooDeclaration : declaration ExtensionsI : extensionsI UL_Accolade_Ouvrante Entetes : entetes UL_Accolade_Fermante
{:
RESULT = new InterfaceDeclaration(declaration, extensionsI, entetes);
:}
;
Classe ::= UL_Class PooDeclaration : declaration Extension : extension Implementations:implementations UL_Accolade_Ouvrante Definitions : definitions UL_Accolade_Fermante
{:
RESULT = new ClasseDeclaration(0, declaration, extension, implementations, definitions);
:}
| FinalOrAbstract : fOrA UL_Class PooDeclaration : declaration Extension : extension Implementations:implementations UL_Accolade_Ouvrante Definitions : definitions UL_Accolade_Fermante
{:
RESULT = new ClasseDeclaration(fOrA, declaration, extension,implementations, definitions);
:}
;
Extension ::= UL_Extends Instanciation:instanciation
{:
RESULT = new Extension(instanciation);
:}
|
{:
RESULT = new Extension();
:}
;
Implementations ::= UL_Implements Instanciations:instanciations
{:
RESULT = instanciations;
:}
|
{:
RESULT = new LinkedList<Instanciation>();
:}
;
FinalOrAbstract ::= UL_Final
{:
RESULT = 2;
:}
| UL_Abstract
{:
RESULT = 1;
:}
;
PooDeclaration ::= UL_Identificateur_Type:name UL_Inferieur GenDeclarations : genDeclarations UL_Superieur
{:
RESULT = new PooDeclaration (name, genDeclarations);
:}
| UL_Identificateur_Type:name
{:
RESULT = new PooDeclaration (name);
:}
;
GenDeclarations ::= GenDeclaration :genDeclaration
{:
LinkedList<GenericTypeDeclaration> result = new LinkedList<GenericTypeDeclaration>();
result.add(genDeclaration);
RESULT = result;
:}
| GenDeclarations:genDeclarations UL_Virgule GenDeclaration :genDeclaration
{:
genDeclarations.add(genDeclaration);
RESULT = genDeclarations;
:}
;
GenDeclaration ::= UL_Identificateur_Type:nom
{:
RESULT = new GenericTypeDeclaration(nom);
:}
| UL_Identificateur_Type:nom ExtendsGenDeclaration:extendsGenDeclaration
{:
RESULT = new GenericTypeDeclaration(nom,extendsGenDeclaration);
:};
ExtendsGenDeclaration ::= Instanciation:instanciation
{:
LinkedList<Instanciation> result = new LinkedList<Instanciation>();
result.add(instanciation);
RESULT = result;
:}
| ExtendsGenDeclaration : extendsGenDeclaration UL_Esperluette Instanciation : instanciation
{:
extendsGenDeclaration.add(instanciation);
RESULT = extendsGenDeclaration;
:}
;
ExtensionsI ::= UL_Extends Instanciations : instanciations
{:
RESULT = instanciations;
:}
|{:
RESULT = new LinkedList<Instanciation>();
:}
;
Instanciation ::= UL_Identificateur_Type:nom
{:
RESULT = new Instanciation(nom);
:}
| UL_Identificateur_Type:nom UL_Inferieur Instanciations:instanciations UL_Superieur
{:
RESULT = new Instanciation(nom,instanciations);
:}
;
Instanciations ::= Instanciation:instanciation
{:
LinkedList<Instanciation> result = new LinkedList<Instanciation>();
result.add(instanciation);
RESULT = result;
:}
| Instanciations:instanciations UL_Virgule Instanciation:instanciation
{:
instanciations.add(instanciation);
RESULT = instanciations;
:}
;
Entetes ::= Entetes:entetes Entete:entete UL_Point_Virgule
{:
entetes.add(entete);
RESULT = entetes;
:}
|{:
RESULT = new LinkedList<MethodeSignature>();
:}
;
Entete ::= Type:type UL_Identificateur:nom UL_Parenthese_Ouvrante Parameters: parameters UL_Parenthese_Fermante
{:
RESULT = new MethodeSignature(nom,type,parameters);
:}
| Type:type UL_Identificateur:nom UL_Parenthese_Ouvrante UL_Parenthese_Fermante
{:
RESULT = new MethodeSignature(nom,type,null);
:}
| Type:type UL_Identificateur:nom UL_Parenthese_Ouvrante UL_ARGS UL_Parenthese_Fermante
{:
RESULT = new MethodeSignature(nom,type,null);
:}
;
Definitions ::= Definitions:definitions Definition:definition
{:
definitions.add(definition);
RESULT = definitions;
:}
|
{:
RESULT = new LinkedList<Definition>();
:}
;
Definition ::= PublicOrPrivate:publicOrPrivate Static:isStatic UL_Final AttributFinal:attribut
{:
RESULT = new Definition(publicOrPrivate,isStatic,2,attribut);
:}
|PublicOrPrivate:publicOrPrivate Static:isStatic Attribut:attribut
{:
RESULT = new Definition(publicOrPrivate,isStatic,0,attribut);
:}
| PublicOrPrivate:publicOrPrivate Static:isStatic UL_Final Methode:methode
{:
RESULT = new Definition(publicOrPrivate,isStatic,2,methode);
:}
| PublicOrPrivate:publicOrPrivate Static:isStatic UL_Abstract Methode:methode
{:
RESULT = new Definition(publicOrPrivate,isStatic,1,methode);
:}
| PublicOrPrivate:publicOrPrivate Static:isStatic Methode:methode
{:
RESULT = new Definition(publicOrPrivate,isStatic,0,methode);
:}
| PublicOrPrivate:publicOrPrivate UL_Construct Instanciation:instanciation UL_Parenthese_Ouvrante Parameters:params UL_Parenthese_Fermante Bloc:bloc
{:
Constructor construct = new Constructor(instanciation,params,bloc);
RESULT = new Definition(publicOrPrivate,construct);
:}
| PublicOrPrivate:publicOrPrivate UL_Construct Instanciation:instanciation UL_Parenthese_Ouvrante UL_Parenthese_Fermante Bloc:bloc
{:
Constructor construct = new Constructor(instanciation,null,bloc);
RESULT = new Definition(publicOrPrivate,construct);
:}
;
Static ::= UL_Static
{:
RESULT = true;
:}
|
{:
RESULT = false;
:}
;
PublicOrPrivate ::= UL_Public
{:
RESULT = true;
:}
| UL_Private
{:
RESULT = false;
:}
;
Methode ::= Entete:entete Bloc:bloc
{:
RESULT = new Methode(entete,bloc,1);
:}
| Entete:entete UL_Point_Virgule
{:
RESULT = new Methode(entete,0);
:}
;
Attribut ::= Type:type UL_Identificateur:ident UL_Point_Virgule
{:
RESULT = new Attribut(type,ident);
:}
| Type:type UL_Identificateur:ident UL_Egal Expression:expression UL_Point_Virgule
{:
RESULT = new Attribut(type,ident,expression,false);
:}
|Instanciation:instanciation UL_Identificateur:ident UL_Egal Expression:expression UL_Point_Virgule
{:
RESULT = new Attribut(instanciation,ident,expression,false);
:}
;
AttributFinal ::= Type:type UL_Identificateur:ident UL_Egal Expression:expression UL_Point_Virgule
{:
RESULT = new Attribut(type,ident,expression,true);
:}
;
Bloc ::= UL_Accolade_Ouvrante Instructions:instructions UL_Accolade_Fermante
{:
RESULT = new Block( instructions );
:}
;
Champ ::= Type:type Identifiant:identifiant UL_Point_Virgule
{:
Type _type = identifiant.getRight();
if (_type == null) {
_type = type;
} else {
_type = ((PartialType)_type).complete( type );
}
RESULT = new FieldDeclaration( identifiant.getLeft(), _type);
:}
;
Champs ::= Champs:champs Champ:champ
{:
champs.add(champ);
RESULT = champs;
:}
| Champ:champ
{:
List<FieldDeclaration> _champs = new LinkedList<FieldDeclaration>();
_champs.add(champ);
RESULT = _champs;
:}
;
Etiquette ::= UL_Identificateur:nom
{:
RESULT = new LabelDeclaration( nom );
:}
;
Etiquettes ::= Etiquettes:etiquettes UL_Virgule Etiquette:etiquette
{:
etiquettes.add(etiquette);
RESULT = etiquettes;
:}
| Etiquette:etiquette
{:
List<LabelDeclaration> _etiquettes = new LinkedList<LabelDeclaration>();
_etiquettes.add(etiquette);
RESULT = _etiquettes;
:}
;
Atomique ::= UL_Type_Booleen
{:
RESULT = AtomicType.BooleanType;
:}
| UL_Type_Caractere
{:
RESULT = AtomicType.CharacterType;
:}
| UL_Type_Chaine
{:
RESULT = AtomicType.StringType;
:}
| UL_Type_Entier
{:
RESULT = AtomicType.IntegerType;
:}
| UL_Type_Flottant
{:
RESULT = AtomicType.FloatingType;
:}
| UL_Type_Vide
{:
RESULT = AtomicType.VoidType;
:}
;
Type ::= Atomique:atomique
{:
RESULT = atomique;
:}
| UL_Enumeration UL_Identificateur_Type:nom UL_Accolade_Ouvrante Etiquettes:etiquettes UL_Accolade_Fermante
{:
RESULT = new EnumerationType( nom, etiquettes );
:}
;
Instructions ::= Instructions:instructions Instruction:instruction
{:
instructions.add( instruction );
RESULT = instructions;
:}
|
{: RESULT = new LinkedList<Instruction>(); :}
;
Identifiant ::= UL_Identificateur:nom
{:
RESULT = new Pair<String,PartialType>( nom, null );
:}
| Identifiant:identifiant UL_Crochet_Ouvrant UL_Crochet_Fermant
{:
if (identifiant.getRight() == null) {
identifiant.setRight( new PartialArrayType() );
} else {
identifiant.getRight().enrich(new PartialArrayType());
}
RESULT = identifiant;
:}
| UL_Parenthese_Ouvrante Identifiant:identifiant UL_Parenthese_Fermante
{:
RESULT = identifiant;
:}
;
Parameters ::= Parameters:parameters UL_Virgule Type:type Identifiant:identifiant
{:
Type _type = identifiant.getRight();
if (_type == null) {
_type = type;
} else {
_type = ((PartialType)_type).complete( type );
}
parameters.add( new ParameterDeclaration( identifiant.getLeft(), _type) );
RESULT = parameters;
:}
| Type:type Identifiant:identifiant
{:
List<ParameterDeclaration> _parameters = new LinkedList<ParameterDeclaration>();
Type _type = identifiant.getRight();
if (_type == null) {
_type = type;
} else {
_type = ((PartialType)_type).complete( type );
}
_parameters.add( new ParameterDeclaration( identifiant.getLeft(), _type) );
RESULT = _parameters;
:}
;
Declaration ::= Type:type Identifiant:identifiant UL_Egal Expression:valeur UL_Point_Virgule
{:
Type _type = identifiant.getRight();
if (_type == null) {
_type = type;
} else {
_type = ((PartialType)_type).complete( type );
}
RESULT = new VariableDeclaration( identifiant.getLeft(), _type, valeur);
:}
| Instanciation:instanciation Identifiant:identifiant UL_Egal Expression:valeur UL_Point_Virgule
{:
Type _type = identifiant.getRight();
if (_type == null) {
_type = instanciation;
} else {
_type = ((PartialType)_type).complete( instanciation );
}
RESULT = new VariableDeclaration( identifiant.getLeft(), _type, valeur);
:}
;
Instruction ::= Declaration:declaration
{:
RESULT = declaration;
:}
| Affectable:affectable UL_Egal Expression:expression UL_Point_Virgule
{:
RESULT = new Assignment( affectable, expression);
:}
| UL_Afficher Expression:expression UL_Point_Virgule
{:
RESULT = new Printer( expression );
:}
| UL_Si UL_Parenthese_Ouvrante Expression:condition UL_Parenthese_Fermante Bloc:alors UL_Sinon Bloc:sinon
{:
RESULT = new Conditional( condition, alors, sinon);
:}
| UL_Si UL_Parenthese_Ouvrante Expression:condition UL_Parenthese_Fermante Bloc:alors
{:
RESULT = new Conditional( condition, alors);
:}
| UL_Tant_Que UL_Parenthese_Ouvrante Expression:condition UL_Parenthese_Fermante Bloc:corps
{:
RESULT = new Repetition( condition, corps);
:}
| UL_Retour Expression:expression UL_Point_Virgule
{:
RESULT = new Return( expression);
:}
|UL_SUPER UL_Parenthese_Ouvrante UL_Parenthese_Fermante UL_Point_Virgule
{:
RESULT = new SuperClass();
:}
|UL_SUPER UL_Parenthese_Ouvrante Expressions:parametres UL_Parenthese_Fermante UL_Point_Virgule
{:
RESULT = new SuperClass(parametres);
:}
;
Expressions ::= Expressions:expressions UL_Virgule Expression:expression
{:
expressions.add( expression );
RESULT = expressions;
:}
| Expression:expression
{:
List<Expression> _expressions = new LinkedList<Expression>();
_expressions.add( expression );
RESULT = _expressions;
:}
;
Affectable ::= UL_Identificateur:nom
{:
RESULT = new VariableAssignment( nom );
:}
| UL_This UL_Point UL_Identificateur:attribut
{:
RESULT = new AttributAssignement(attribut);
:}
| Affectable:tableau UL_Crochet_Ouvrant Expression:indice UL_Crochet_Fermant
{:
RESULT = new ArrayAssignment( tableau, indice);
:}
| UL_Parenthese_Ouvrante Affectable:affectable UL_Parenthese_Fermante
{:
RESULT = affectable;
:}
| UL_Parenthese_Ouvrante Type:type UL_Parenthese_Fermante Affectable:affectable
{:
RESULT = new AssignableConversion( affectable, type);
:}
| Affectable:enregistrement UL_Point UL_Identificateur:etiquette
{:
RESULT = new FieldAssignment( enregistrement, etiquette);
:}
;
Expression ::= /*Affectable:affectable UL_Egal Expression:expression
{:
RESULT = new Assignment( affectable, expression);
:}
| */ Expression:gauche UL_Double_Egal Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Equals, droite);
:}
| Expression:gauche UL_Exclamation_Egal Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Different, droite);
:}
| Expression:gauche UL_Inferieur Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Lesser, droite);
:}
| Expression:gauche UL_Superieur Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Greater, droite);
:}
| Expression:gauche UL_Inferieur_Egal Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.LesserOrEqual, droite);
:}
| Expression:gauche UL_Superieur_Egal Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.GreaterOrEqual, droite);
:}
| Expression:gauche UL_Double_Barre Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Or, droite);
:}
| Expression:gauche UL_Double_Esperluette Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.And, droite);
:}
| Expression:gauche UL_Plus Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Add, droite);
:}
| Expression:gauche UL_Moins Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Substract, droite);
:}
| Expression:gauche UL_Asterisque Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Multiply, droite);
:}
| Expression:gauche UL_Oblique Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Divide, droite);
:}
| Expression:gauche UL_Pour_Cent Expression:droite
{:
RESULT = new BinaryExpression( gauche, BinaryOperator.Modulo, droite);
:}
| UL_Moins Expression:expression
{:
RESULT = new UnaryExpression( UnaryOperator.Opposite, expression);
:}
| UL_Point_Exclamation Expression:expression
{:
RESULT = new UnaryExpression( UnaryOperator.Negate, expression);
:}
| Expression:expression UL_Crochet_Ouvrant Expression:indice UL_Crochet_Fermant
{:
RESULT = new ArrayAccess( expression, indice );
:}
// | Expression:expression UL_Point UL_Identificateur:etiquette ///////////////////////////// conflicts////////////////////
// {:
// RESULT = new FieldAccess( expression, etiquette );
// :}
| Expression:expression UL_Point UL_Identificateur:attribut
{:
RESULT = new AttributAccess(expression, attribut);
:}
| UL_This UL_Point UL_Identificateur:attribut
{:
RESULT = new AttributAssignement(attribut);
:}
| Expression:condition UL_Point_Interrogation Expression:alors UL_Deux_Points Expression:sinon
{:
RESULT = new ConditionalExpression( condition, alors, sinon);
:}
| UL_Parenthese_Ouvrante Expression:expression UL_Parenthese_Fermante
{:
RESULT = expression;
:}
| UL_Parenthese_Ouvrante Type:type UL_Parenthese_Fermante Expression:expression
{:
RESULT = new AccessibleConversion( expression, type);
:}
| UL_Accolade_Ouvrante Expressions:expressions UL_Accolade_Fermante
{:
RESULT = new Sequence( expressions );
:}
| UL_Identificateur:nom
{:
RESULT = new IdentifierAccess( nom );
:}
|
// Expression d'appel de méthode avec paramètres dont le résultat n'est pas de type void
// Il s'agit d'un appel implicite sur l'objet contenu dans this ou sur la classe contenant l'expression en cours d'exécution
// Il faut créer la classe MethodCall pour l'arbre abstrait en s'inspirant de FunctionCall
UL_Identificateur:nom UL_Parenthese_Ouvrante Expressions:parametres UL_Parenthese_Fermante
{:
RESULT = new MethodCall( nom, parametres );
:}
|
// Expression d'appel de méthode sans paramètre dont le résultat n'est pas de type void
// Il s'agit d'un appel implicite sur l'objet contenu dans this ou sur la classe contenant l'expression en cours d'exécution
// Il faut créer la classe MethodCall pour l'arbre abstrait en s'inspirant de FunctionCall
UL_Identificateur:nom UL_Parenthese_Ouvrante UL_Parenthese_Fermante
{:
List<Expression> _parametres = new LinkedList<Expression>();
RESULT = new MethodCall( nom, _parametres );
:}
|
// Expression d'appel de méthode de classe avec paramètres dont le résultat n'est pas de type void
// Il s'agit d'un appel explicite sur une classe
// Il faut créer la classe MethodCall pour l'arbre abstrait en s'inspirant de FunctionCall
Type:type UL_Point UL_Identificateur:nom UL_Parenthese_Ouvrante Expressions:parametres UL_Parenthese_Fermante
{:
RESULT = new MethodCall( type, nom, parametres );
:}
|
// Expression d'appel de méthode de classe sans paramètre dont le résultat n'est pas de type void
// Il s'agit d'un appel explicite sur une classe
// Il faut créer la classe MethodCall pour l'arbre abstrait en s'inspirant de FunctionCall
Type:type UL_Point UL_Identificateur:nom UL_Parenthese_Ouvrante UL_Parenthese_Fermante
{:
List<Expression> _parametres = new LinkedList<Expression>();
RESULT = new MethodCall( type, nom, _parametres );
:}
|
// Expression d'appel de méthode avec paramètres dont le résultat n'est pas de type void
// Il s'agit d'un appel explicite sur un objet
// Il faut créer la classe MethodCall pour l'arbre abstrait en s'inspirant de FunctionCall
Expression:objet UL_Point UL_Identificateur:nom UL_Parenthese_Ouvrante Expressions:parametres UL_Parenthese_Fermante
{:
RESULT = new MethodCall( objet, nom, parametres );
:}
|
// Expression d'appel de méthode sans paramètre dont le résultat n'est pas de type void
// Il s'agit d'un appel explicite sur un objet
// Il faut créer la classe MethodCall pour l'arbre abstrait en s'inspirant de FunctionCall
Expression:objet UL_Point UL_Identificateur:nom UL_Parenthese_Ouvrante UL_Parenthese_Fermante
{:
List<Expression> _parametres = new LinkedList<Expression>();
RESULT = new MethodCall( objet, nom, _parametres );
:}
| UL_Nombre_Entier:entier
{:
RESULT = new IntegerValue( entier );
:}
| UL_Vrai
{:
RESULT = BooleanValue.True;
:}
| UL_Faux
{:
RESULT = BooleanValue.False;
:}
| UL_Nul
{:
RESULT = NullValue.Null;
:}
| UL_Nombre_Flottant:flottant
{:
RESULT = new FloatingValue( flottant );
:}
| UL_Caractere:caractere
{:
RESULT = new CharacterValue( caractere );
:}
| UL_Chaine:chaine
{:
RESULT = new StringValue( chaine );
:}
| UL_Nouveau Type:type UL_Crochet_Ouvrant Expression:taille UL_Crochet_Fermant
{:
RESULT = new ArrayAllocation( type, taille );
:}
| UL_Nouveau Instanciation:instanciation UL_Parenthese_Ouvrante Expressions:parametres UL_Parenthese_Fermante
{:
RESULT = new ConstructorCall(instanciation,parametres);
:}
| UL_Nouveau Instanciation:instanciation UL_Parenthese_Ouvrante UL_Parenthese_Fermante
{:
RESULT = new ConstructorCall(instanciation);
:}
| Instanciation:instanciation
{:
RESULT = instanciation;
:}
;