Repository navigation
Expand file tree
/
Copy pathMCCommonStatements.mc4
More file actions
161 lines (119 loc) · 4.52 KB
/
Copy pathMCCommonStatements.mc4
File metadata and controls
161 lines (119 loc) · 4.52 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
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.statements;
/* This is a MontiCore stable grammar.
* Adaptations -- if any -- are conservative. */
import de.monticore.statements.*;
/**
* This grammar defines typical statements, such as
* method calls (which are actually expressions),
* assignment of variables, if, for, while, switch statements, and blocks.
*
* This embodies a complete structured statement language, however does not
* provide return, assert, exceptions, and low-level constructs like break.
*
* This grammar is part of a hierarchy of statements, namely
* * statements/MCStatementsBasis.mc4
* * -- statements/MCAssertStatements.mc4
* * -- statements/MCVarDeclarationStatements.mc4
* * -- -- statements/MCArrayStatements.mc4
* * -- -- statements/MCCommonStatements.mc4
* * -- -- -- statements/MCExceptionStatements.mc4
* * -- -- -- statements/MCSynchronizedStatements.mc4
* * -- statements/MCLowLevelStatements.mc4
* * -- statements/MCReturnStatements.mc4
*
* and the composition of all statement grammars to full Java:
* * -- -- statements/MCFullJavaStatements.mc4
*
*/
component grammar MCCommonStatements
extends MCVarDeclarationStatements {
/**
* Standard Form of a block { ... }
* it allows to define local variables that are not exported
* and can only be used after defined (typical within code bodies).
*/
scope(non_exporting ordered) MCJavaBlock implements MCStatement
= "{" MCBlockStatement* "}" ;
/**
* All the Java Modifier
* The method getModifier() ensures conservative behaviour with previous
* grammar definition that used an enumeration. The square brackets are
* required to generate the ASTConstantsMCCommonStatements constants.
*/
interface JavaModifier extends MCModifier;
astrule JavaModifier
= method public int getModifier(){};
ModifierPrivate implements JavaModifier
= [private:"private"];
ModifierProtected implements JavaModifier
= [protected:"protected"];
ModifierPublic implements JavaModifier
= [public:"public"];
ModifierStatic implements JavaModifier
= [static:"static"];
ModifierTransient implements JavaModifier
= [transient:"transient"];
ModifierFinal implements JavaModifier
= [final:"final"];
ModifierAbstract implements JavaModifier
= [abstract:"abstract"];
ModifierNative implements JavaModifier
= [native:"native"];
ModifierThreadsafe implements JavaModifier
= [threadsafe:"threadsafe"];
ModifierSynchronized implements JavaModifier
= [synchronized:"synchronized"];
ModifierConst implements JavaModifier
= [const:"const"];
ModifierVolatile implements JavaModifier
= [volatile:"volatile"];
ModifierStrictFp implements JavaModifier
= [strictfp:"strictfp"];
ModifierDefault implements JavaModifier
= [modifier_default:"default"];
IfStatement implements MCStatement
= "if" "(" condition:Expression ")"
thenStatement:MCStatement
("else" elseStatement:MCStatement)? ;
// we use "elseStatement", because the
// generated Java code doesn't allow "else" as Name
scope (non_exporting ordered) ForStatement implements MCStatement
= "for" "(" ForControl ")" MCStatement ;
interface ForControl ;
CommonForControl implements ForControl
= ForInit? ";" condition:Expression? ";" (Expression || ",")* ;
ForInit
= ForInitByExpressions | LocalVariableDeclaration ;
ForInitByExpressions
= (Expression || ",")+ ;
EnhancedForControl implements ForControl
= FormalParameter ":" Expression;
FormalParameter
= MCModifier* MCType Declarator;
WhileStatement implements MCStatement
= "while" "(" condition:Expression ")" MCStatement ;
DoWhileStatement implements MCStatement
= "do" MCStatement "while" "(" condition:Expression ")" ";" ;
SwitchStatement implements MCStatement
= "switch" "(" Expression ")"
"{" SwitchBlockStatementGroup* SwitchLabel* "}" ;
EmptyStatement implements MCStatement
= ";" ;
ExpressionStatement implements MCStatement
= Expression ";" ;
// Matches cases then statements, both of which are mandatory.
// To handle empty cases at the end, SwitchLabel* is explicitly added
// in the statement body
SwitchBlockStatementGroup
= SwitchLabel+ MCBlockStatement+ ;
interface SwitchLabel ;
ConstantExpressionSwitchLabel implements SwitchLabel
= "case" constant:Expression ":" ;
EnumConstantSwitchLabel implements SwitchLabel
= "case" enumConstant:Name ":" ;
DefaultSwitchLabel implements SwitchLabel
= "default" ":" ;
BreakStatement implements MCStatement
= "break" ";" ;
}