RPA Toolkit
c8fbc97580747cd77c3147a38ecfe7a36350be21
[rpatk.git] / tests / ecma262.rpa
1 # Temporary staff
2 NewKeyword                              ::= 'new'
3 ArrayKeyword                    ::= 'Array'
4 NewArrayNoSize                  ::= <S>? <:NewKeyword:> <S> <:ArrayKeyword:> <S>? '(' <S>? ')'
5 NewArraySize                    ::= <S>? <:NewKeyword:> <S> <:ArrayKeyword:> <S>? '(' <S>? <:AssignmentExpression:> <S>? ')'
6 NewArrayExpression              ::= <:NewArraySize:> | <:NewArrayNoSize:>
7
8 # 6 Source Text
9 SourceCharacter         ::= .
10
11 # 7.2 White space
12 WhiteSpace                              ::= [#0x0009] | [#0x000B] | [#0x000C] | [#0x0020] | [#0x00A0] | [#0xFEFF]
13
14 # 7.3 Line Terminators
15 LineTerminator                  ::= [#0x000D] [#0x000A] | [#0x000A] | [#0x000D] | [#0x2028] | [#0x2029]
16 LineTerminatorSequence  ::= [#0x000D] [#0x000A] | [#0x000A] | [#0x000D] | [#0x2028] | [#0x2029]
17 S                                               ::= ( <WhiteSpace> | <LineTerminator> )+
18 SC                                              ::= <S>? ';' <S>?
19 COMMA                                   ::= <S>? ',' <S>?
20 EQ                                              ::= <S>? '=' <S>?
21
22 # 7.4 Comments
23 Comment                         ::= <:MultiLineComment:> | <:SingleLineComment:>
24 MultiLineComment                ::= '/*' <:MultiLineCommentChar:>* '*/'
25 MultiLineCommentChar    ::= . - '*/'
26 SingleLineComment               ::= '#' <:SingleLineCommentChar:>*
27 SingleLineCommentChar   ::= <SourceCharacter> - <LineTerminator>
28
29 # 7.5 Tokens
30 Token                                   ::= <:IdentifierName:> |
31                                                 <:Punctuator:> |
32                                                 <:NumericLiteral:> |
33                                                 <:StringLiteral:>
34
35 # 7.6 Identifier Names and Identifiers
36
37 Identifier                              ::= <IdentifierName> - <ReservedWord> - <ReservedWord> <IdentifierPart>
38 IdentifierName                  ::= <IdentifierStart> <IdentifierPart>*
39 IdentifierStart         ::= <UnicodeLetter> | '$' | '_' | '\' <:UnicodeEscapeSequence:>
40 UnicodeLetter                   ::= <Lu> |
41                         <Ll> |
42                         <Lt> |
43                         <Lm> |
44                         <Lo> |
45                         <Nl>
46
47 Lu                                              ::= [#0x0041-#0x005A] | [#0x00C0-#0x00DE] | [#0x0100-#0x0232]   # TBD
48 Ll                                              ::= [#0x0061-#0x007A] | [#0x00C0-#0x00DE]                                               # TBD
49 IdentifierPart                  ::= <IdentifierStart> | 
50                                                         <:UnicodeCombiningMark:> |
51                                                         <:UnicodeDigit:> | 
52                                                         <:UnicodeConnectorPunctuation:>                                                         # TBD
53 UnicodeDigit            ::= [0-9] | [#0x0660-#0x0669]                                   # TBD
54
55 ReservedWord                    ::= <:Keyword:>
56                                                         <:FutureReservedWord:> |
57                                                         <:NullLiteral:> |
58                                                         <:BooleanLiteral:>
59
60 Keyword                         ::= 'instanceof' | 'typeof'     | 'break' |
61                                                 'do' | 'new' | 'var' |
62                                                 'case' | 'else' | 'return' | 'void' | 
63                                                 'catch' | 'finally' | 'continue' | 'for' | 
64                                                 'switch' | 'while' | 'this' | 'with' | 
65                                                 'debugger' | 'function' | 'throw' | 'default' |  
66                                                 'if' | 'try' | 'delete' | 'in'
67
68 FutureReservedWord                      ::= 'class' | 'enum' | 'extends' | 'import' | 'const' | 'export' |
69                                                         'implements' | 'let' | 'private' | 'public' |
70                                 'static' | 'interface' | 'package' | 'protected'
71
72 NullLiteral                                     ::= 'null'
73 BooleanLiteral                          ::= 'true' | 'false'
74 Literal                                         ::= <:NullLiteral:> |
75                                                         <:BooleanLiteral:> |
76                                                         <:NumericLiteral:> |
77                                                         <:StringLiteral:> |
78                                                         <:RegularExpressionLiteral:>
79                                                         
80 LiteralOp                                       ::= <:Literal:>
81
82 # 7.8.3 Numeric Literals
83
84 NumericLiteral                                  ::= <:HexIntegerLiteral:> | <:DecimalNonIntegerLiteral:> | <:DecimalIntegerLiteral:>
85 DecimalNonIntegerLiteral                ::= ('0' | <:NonZeroDigit:> <DecimalDigits>?) '.' <DecimalDigits>? <:ExponentPart:>? |
86                                                                 '.' <:DecimalDigits:> <:ExponentPart:>? 
87 DecimalIntegerLiteral                   ::= '0' | <:NonZeroDigit:> <:DecimalDigits:>? <:ExponentPart:>?
88 DecimalDigits                                   ::= <:DecimalDigit:>+
89 DecimalDigit                                    ::= [0-9]
90 NonZeroDigit                                    ::= [1-9]
91 ExponentPart                                    ::= <:ExponentIndicator:> <:SignedInteger:>
92 ExponentIndicator                               ::= [eE]
93 SignedInteger                                   ::= '-' <:DecimalDigits:> |
94                                                                 '+' <:DecimalDigits:> |
95                                                                 <:DecimalDigits:>
96 HexIntegerLiteral                               ::= '0' [xX] <:HexDigit:>+
97 HexDigit                                                ::= [0-9a-fA-F]
98
99 # 7.8.4 String Literals
100 StringLiteral                                   ::= '\"' <:DoubleStringCharacters:>? '\"' |
101                                                                 ['] <:SingleStringCharacters:>? [']
102
103 DoubleStringCharacters                  ::= <DoubleStringCharacter>+
104 SingleStringCharacters                  ::= <SingleStringCharacter>+
105
106 DoubleStringCharacter                   ::= '\\' <:EscapeSequence:> |
107                                                                 <:LineContinuation:> |
108                                                                 <:SourceCharacter:> - ('\"' | '\\' | <:LineTerminator:>)
109
110 SingleStringCharacter                   ::= '\\' <:EscapeSequence:> |
111                                                                 <:LineContinuation:> |
112                                                                 <:SourceCharacter:> - (['] | '\\' | <:LineTerminator:>)
113
114 BracketExpressionOp                             ::= '(' <S>? <:Expression:> <S>? ')'
115
116 PrimaryExpression                               ::= 'this' | 
117                                                                 '(' <S>? <:Expression:> <S>? ')' |
118                                                                 <:LiteralOp:> |
119                                                                 (<;SwiIdExist;> & <:SwiId:>) |
120                                                                 <:IdentifierOp:>
121
122 # The next line is mine
123 IdentifierOp                                    ::= <:Identifier:> 
124 SwiId                                                   ::= <:Identifier:> 
125 SwiIdExist                                              ::= <SwiId> 
126
127
128 ArrayLiteral                                    ::= '[' <S>? <:Elision:>? <S>? ']' |
129                                                                 '[' <S>? <:ElementList:> <S>? ']' |
130                                                                 '[' <S>? <:ElementList:> <S>? ',' <S>? <:Elision:> <S>? ']'
131 ElementList                                             ::= <:Elision:>? <S>? <:AssignmentExpression:> (<S>? ',' <S>? <:Elision:>? <S>? <:AssignmentExpression:> )*
132 Elision                                                 ::= ',' <S>? <:Elision:> | <S>? ','
133
134
135 # 11.2 Left-Hand-Side Expressions
136 NewKeyword                                              ::= 'new' - 'new' <IdentifierPart>
137 LSB                                                             ::= <S>? '[' <S>?
138 RSB                                                             ::= <S>? ']' <S>?
139 dot                                                             ::= '.'
140 MemberIdentifierNameOp                  ::= <:Identifier:>
141 MemberIdentifierNameLookupOp    ::= <:Identifier:>
142 MemberExpressionBaseOp                  ::= <:MemberExpression:>
143 MemberExpressionIndexOp                 ::= <:MemberExpressionBaseOp:>  <:LSB:> <:Expression:> <:RSB:>
144 MemberExpressionNameOp                  ::= <:MemberExpressionBaseOp:> <:dot:> <:MemberIdentifierNameOp:>
145
146 MemberExpression                                ::= <:MemberExpressionIndexOp:>  |
147                                                                         <:MemberExpressionNameOp:> |
148                                                                         <:NewKeyword:> <S>? <:MemberExpression:> <S>? <:ArgumentsOp:> |
149                                                                         <:FunctionExpression:> |
150                                                                         <:PrimaryExpression:>
151
152
153 NewExpression                                   ::= <:NewArrayExpression:> |
154                                                                         <:NewKeyword:> <S>? <:NewExpression:> |
155                                                                         <:MemberExpression:>
156
157
158 FunctionCallName                                ::= <:CallExpression:> | <:MemberExpression:>
159 CallExpressionOp                                ::= <:FunctionCallName:> <S>? <:ArgumentsOp:>
160 CallExpressionBaseOp                    ::= <:CallExpression:>
161 CallExpressionIndexOp                   ::= <:CallExpressionBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
162 CallExpressionNameOp                    ::= <:CallExpressionBaseOp:> '.' <:MemberIdentifierNameOp:>
163
164 CallExpression                                  ::= <:CallExpressionIndexOp:> |
165                                                                         <:CallExpressionNameOp:> |
166                                                                         <:CallExpressionOp:>
167
168 ArgumentsOp                                             ::= '(' <S>? ')' |
169                                                                 '(' <S>? <:ArgumentList:> <S>? ')'
170 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:AssignmentExpression:> |
171                                                                         <:AssignmentExpression:>
172
173 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:FunctionCallParameter:> |
174                                                                         <:FunctionCallParameter:>
175 FunctionCallParameter                   ::= <:AssignmentExpression:>
176                                                                         
177 ValLeftHandSideExpression               ::= <:CallExpression:> | <:NewExpression:>
178 AddressLeftHandSideExpression   ::= <:ValLeftHandSideExpression:>
179 LeftHandSideExpression                  ::= <:AddressLeftHandSideExpression:>
180
181
182 # 11.3 Postfix Expressions
183 # RULE: LeftHandSideExpression always ends up in R0 (Let see if this would work)
184 PostfixOperator                                 ::= '++' | '--'
185 PostfixExpressionOp                     ::= <:LeftHandSideExpression:> <:PostfixOperator:>
186 PostfixExpressionValOp                  ::= <:ValLeftHandSideExpression:>
187 PostfixExpression                               ::= <:PostfixExpressionOp:> |
188                                                                         <:PostfixExpressionValOp:> 
189
190 PrefixOperator                                  ::= <:PostfixOperator:>
191 PrefixExpressionOp                              ::= <:PrefixOperator:> <:LeftHandSideExpression:>
192 PrefixExpression                                ::= <:PrefixExpressionOp:>
193
194 # 11.4 Unary Operators
195 UnaryOperatorOpcode                             ::= '~' | '!' | ('+' - '++') | ('-' - '--') | 'delete' | 'void' | 'typeof'
196 UnaryOperator                           ::= <:UnaryOperatorOpcode:>
197 UnaryExpressionOp                       ::=     <S>? <:UnaryOperator:> <S>? <:UnaryExpression:>
198 UnaryExpression                         ::=     <:UnaryExpressionOp:> | <:PrefixExpression:> | <:PostfixExpression:>
199
200
201 # 11.5 Multiplicative Operators
202 MultiplicativeOperator                  ::= '*' | '/' | '%'
203 MultiplicativeExpressionOp              ::= <:MultiplicativeExpression:> <S>? <:MultiplicativeOperator:> <S>? <:UnaryExpression:>
204 MultiplicativeExpression                ::= <:MultiplicativeExpressionOp:> | 
205                                                                         <:UnaryExpression:>
206
207 # 11.6 Additive Operators
208 AdditiveOperator                                ::= '+' | '-'
209 AdditiveExpressionOp                    ::= <:AdditiveExpression:> <S>? <:AdditiveOperator:> <S>? <:MultiplicativeExpression:>
210 AdditiveExpression                              ::= <:AdditiveExpressionOp:> | 
211                                                                         <:MultiplicativeExpression:>
212
213
214 11.7 Bitwise Shift Operators
215 ShiftOperator                                   ::= '>>>' | '<<' | '>>'
216 ShiftExpressionOp                               ::= <:ShiftExpression:> <S>? <:ShiftOperator:> <S>? <:AdditiveExpression:>
217 ShiftExpression                                 ::= <:ShiftExpressionOp:> |
218                                                                 <:AdditiveExpression:> 
219
220
221 # 11.8 Relational Operators
222 RelationalOperator                              ::= '<=' | '>=' | '<' | '>' | 'instanceof'
223 RelationalExpressionOp                  ::= <:RelationalExpression:> <S>? <:RelationalOperator:> <S>? <:ShiftExpression:>
224 RelationalExpression                    ::= <:RelationalExpressionOp:> |
225                                                                 <:ShiftExpression:>
226
227 # 11.9 Equality Operators
228 EqualityOperator                                ::= '===' | '==' | '!==' | '!='
229 EqualityExpressionOp                    ::= <:EqualityExpression:> <S>? <:EqualityOperator:> <S>? <:RelationalExpression:> 
230 EqualityExpression                              ::= <:EqualityExpressionOp:> |
231                                                                 <:RelationalExpression:>
232
233 BitwiseANDOperator                              ::= '&' - '&&'
234 BitwiseANDOp                                    ::= <:BitwiseANDExpression:> <S>? <:BitwiseANDOperator:> <S>? <:EqualityExpression:>
235 BitwiseANDExpression                    ::= <:BitwiseANDOp:> |
236                                                                 <:EqualityExpression:>
237
238 BitwiseXOROperator                              ::= '^'
239 BitwiseXOROp                                    ::= <:BitwiseXORExpression:> <S>? <:BitwiseXOROperator:> <S>? <:BitwiseANDExpression:>
240 BitwiseXORExpression                    ::= <:BitwiseXOROp:> |
241                                                                 <:BitwiseANDExpression:>
242
243 BitwiseOROperator                               ::= '|' - '||'
244 BitwiseOROp                                             ::= <:BitwiseORExpression:> <S>? <:BitwiseOROperator:> <S>? <:BitwiseXORExpression:>
245 BitwiseORExpression                     ::= <:BitwiseOROp:> |
246                                                                 <:BitwiseXORExpression:>
247
248 # 11.11 Binary Logical Operators
249 LogicalANDOperator                              ::= '&&'
250 LogicalANDOp                                    ::= <:LogicalANDExpression:> <S>? <:LogicalANDOperator:>  <S>? <:BitwiseORExpression:>
251 LogicalANDExpression                    ::= <:LogicalANDOp:> |
252                                                                 <:BitwiseORExpression:>
253
254 LogicalOROperator                               ::= '||'
255 LogicalOROp                                             ::= <:LogicalORExpression:> <S>? <:LogicalOROperator:> <S>? <:LogicalANDExpression:>
256 LogicalORExpression                     ::= <:LogicalOROp:> |
257                                                                 <:LogicalANDExpression:>
258
259
260 # 11.12 Conditional Operator ( ? : )
261 AssignmentExpressionIfTrueOp            ::= <:AssignmentExpression:>
262 AssignmentExpressionIfFalseOp           ::= <:AssignmentExpression:>
263 QuestionMarkOp                                          ::= '?'
264 ConditionalExpression                           ::= <:LogicalORExpression:> (<S>? <:QuestionMarkOp:> <S>? <:AssignmentExpressionIfTrueOp:> <S>? ':' <S>? <:AssignmentExpressionIfFalseOp:>)?
265
266 # 11.13 Assignment Operators
267 LeftHandSideExpressionPush              ::= <:LeftHandSideExpression:>
268 IdentifierAddressPush                   ::= <:Identifier:>
269 AssignmentExpressionOp                  ::= <:LeftHandSideExpressionPush:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpression:>
270 AssignmentExpression                    ::= <:AssignmentExpressionOp:> | 
271                                                                         <:ConditionalExpression:>
272
273 AssignmentExpressionNoIn                ::= <:LeftHandSideExpression:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpressionNoIn:> | <:ConditionalExpressionNoIn:>
274 AssignmentOperator                              ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
275
276
277 # 11.14 Comma Operator  ( , )
278 Expression              ::= <:AssignmentExpression:> ( <S>? ',' <S>? <:AssignmentExpression:> )*
279 ExpressionNoIn          ::= <:AssignmentExpressionNoIn:> ( <S>? ',' <S>? <:AssignmentExpressionNoIn:> )*
280
281
282 # 12 Statements
283 Statement                                               ::= <:BreakStatement:> |
284                                                                         <:ContinueStatement:> |
285                                                                         <:Block:> |
286                                                                 <:Comment:> |
287                                                                 <:VariableStatement:> |
288                                                                 <:EmptyStatement:> |
289                                                                 <:ExpressionStatement:> |
290                                                                 <:IfStatement:> |
291                                                                 <:IterationStatement:> |
292                                                                 <:ContinueStatement:> |
293                                                                 <:BreakStatement:> |
294                                                                 <:ReturnStatement:> |
295                                                                 <:ImportStatement:> |
296                                                                 <:WithStatement:> |
297                                                                 <:LabelledStatement:> |
298                                                                 <:SwitchStatement:> |
299                                                                 <:ThrowStatement:> |
300                                                                 <:TryStatement:> |
301                                                                 <:DebuggerStatement:>
302
303 # 12.1 Block
304 BlockBegin                                                      ::= <S>? '{' <S>?
305 BlockEnd                                                        ::= <S>? '}' <S>?
306 Block                                                           ::= <:BlockBegin:> <:StatementList:>? <:BlockEnd:>
307 StatementList                                           ::= (<S>? <:Statement:>)+
308
309 # 12.2 Variable Statement
310 VariableStatement                                       ::= 'var' <S>? <:VariableDeclarationList:> <:SC:>
311 VariableDeclarationList                         ::= <:VariableDeclaration:> (<:COMMA:> <:VariableDeclaration:> )*
312 VariableAllocate                                        ::= <:Identifier:>
313 VariableAllocateAndInit                         ::= <:Identifier:>
314 VariableDeclaration                                     ::= <:VariableAllocateAndInit:> <:Initialiser:> | <:VariableAllocate:>
315 Initialiser                                                     ::= <:EQ:> <:AssignmentExpression:>
316
317
318 # 12.3 Empty Statement
319 EmptyStatement                                          ::= <:SC:>
320
321 # 12.4 Expression Statement
322 ExpressionStatement                             ::= (<:Expression:> - ('function' | '{')) <:SC:>
323
324
325 # 12.5 The if Statement
326
327 ElseOp                                                          ::= 'else'
328 IfConditionOp                                           ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'
329 IfOp                                                            ::= <:IfConditionOp:> <S>? <:Statement:>
330 IfElseOp                                                        ::= <:IfConditionOp:> <S>? <:Statement:> <S>? <:ElseOp:> <S>? <:Statement:>
331
332 IfStatement                                                     ::= <:IfElseOp:> |
333                                                                                 <:IfOp:>
334
335 # 12.6 Iteration Statements
336 # 12.6a Iteration do ... while() 
337 WhileKeyword                                            ::= 'while'
338 WhileExpression                                         ::= <:WhileKeyword:> <S>? '(' <S>? <:Expression:> <S>? ')'
339 DoKeyword                                                       ::= 'do'
340 IterationDo                                                     ::= <:DoKeyword:> <S>? <:Statement:> <S>? <:WhileExpression:> (<S>? ';')
341
342 # 12.6b Iteration while()
343 WhileConditionOp                                        ::= 'while' <S>? '(' <S>? <:Expression:> <S>? ')'
344 IterationWhileOp                                        ::= <:WhileConditionOp:> <S>? <:Statement:>
345
346 # 12.6c Iteration for ( ; ; )
347 ForKeyword                                                      ::= 'for'
348 ExpressionNoIn                                          ::= <:Expression:>
349 ForExpressionInitOp                                     ::= ('var' <S>? <:VariableDeclarationList:>) | <:ExpressionNoIn:>
350 ForExpressionCompareOp                          ::= <:Expression:>
351 ForExpressionIncrementOp                        ::= <:Expression:>
352
353 # The following & expression is done in order to swap the places of the code generated for the comparison and increment.
354 # This is done by selectively turning on/off callbacks in both statement so that the final result appears as if the
355 # <:ForExpressionCompareOp:> <:ForExpressionIncrementOp:> appear in the opposite order.
356 ForIterationStatementOp                         ::= <:ForKeyword:> <S>? '(' <S>? <:ForExpressionInitOp:>? <S>? ';' <S>? <ForExpressionCompareOp>? <S>? ';' <S>? <:ForExpressionIncrementOp:>? <S>? ')' &
357                                                                                 <ForKeyword> <S>? '(' <S>? <ForExpressionInitOp>? <S>? ';' <S>? <:ForExpressionCompareOp:>? <S>? ';' <S>? <ForExpressionIncrementOp>? <S>? ')'
358 IterationForOp                                          ::= <:ForIterationStatementOp:> <S>? <:Statement:>
359
360
361 IterationStatement                                      ::= <:IterationWhileOp:> |
362                                                                                 <:IterationForOp:> |
363                                                                         <:IterationDo:>
364
365 # 12.9 The return Statement
366 ReturnOp                                                ::= ('return' - 'return' <:IdentifierPart:>) <WhiteSpace>* <:AssignmentExpression:>? (<S>? ';')
367 ReturnStatement                                 ::= <:ReturnOp:>
368
369 # The Break Statement
370 BreakOp                                                 ::= 'break' - 'break' <:IdentifierPart:>
371 BreakStatement                                  ::= <S>? <:BreakOp:> <:SC:>
372
373 # The Continue Statement
374 ContinueOp                                              ::= 'continue' - 'continue' <:IdentifierPart:>
375 ContinueStatement                               ::= <S>? <:ContinueOp:> <:SC:>
376
377
378 # 13 Function Definition
379 FunctionName                                            ::= <:Identifier:>
380 FunctionDefinition                                      ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionName:><S>?'('<S>?<:FormalParameterList:>?<S>?')'
381 FunctionDeclaration                                     ::= <:FunctionDefinition:><S>?'{'<S>?<:FunctionBody:>?<S>?'}'
382 FunctionExpression                                      ::= ('function' - 'function'<IdentifierPart>)<S>?<:FunctionName:>?<S>?'('<S>?<:FormalParameterList:>?<S>?')'<S>?'{'<S>?<:FunctionBody:>?<S>?'}'
383 FunctionParameter                                       ::= <:Identifier:>
384 FormalParameterList                             ::= <:FunctionParameter:> ( <S>? ',' <S>? <:FunctionParameter:> )*
385 FunctionBody                                            ::= <:SourceElements:>
386
387
388 # 14 Program
389 SourceElements                                  ::= (<S>? <:SourceElement:>)+
390 SourceElement                                           ::= <:FunctionDeclaration:> |
391                                                                         <:Statement:>
392 Program                                                 ::= <:SourceElements:>
393 # The root rule, it is anonymous
394 <:Program:>
395         
396