RPA Toolkit
work on new object
[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 MemberExpressionNewOp                   ::= <:NewKeyword:> <S>? <:CallExpression:>
146
147 MemberExpression                                ::= <:MemberExpressionIndexOp:>  |
148                                                                         <:MemberExpressionNameOp:> |
149                                                                         <:MemberExpressionNewOp:> |
150                                                                         <:FunctionExpression:> |
151                                                                         <:PrimaryExpression:>
152
153
154 NewExpression                                   ::= <:NewArrayExpression:> |
155                                                                         <:NewKeyword:> <S>? <:NewExpression:> |
156                                                                         <:MemberExpression:>
157
158
159 FunctionCallName                                ::= <:CallExpression:> | <:MemberExpression:>
160 CallExpressionOp                                ::= <:FunctionCallName:> <S>? <:ArgumentsOp:>
161 CallExpressionBaseOp                    ::= <:CallExpression:>
162 CallExpressionIndexOp                   ::= <:CallExpressionBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
163 CallExpressionNameOp                    ::= <:CallExpressionBaseOp:> '.' <:MemberIdentifierNameOp:>
164
165 CallExpression                                  ::= <:CallExpressionIndexOp:> |
166                                                                         <:CallExpressionNameOp:> |
167                                                                         <:CallExpressionOp:>
168
169 ArgumentsOp                                             ::= '(' <S>? ')' |
170                                                                 '(' <S>? <:ArgumentList:> <S>? ')'
171 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:AssignmentExpression:> |
172                                                                         <:AssignmentExpression:>
173
174 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:FunctionCallParameter:> |
175                                                                         <:FunctionCallParameter:>
176 FunctionCallParameter                   ::= <:AssignmentExpression:>
177                                                                         
178 ValLeftHandSideExpression               ::= <:CallExpression:> | <:NewExpression:>
179 AddressLeftHandSideExpression   ::= <:ValLeftHandSideExpression:>
180 LeftHandSideExpression                  ::= <:AddressLeftHandSideExpression:>
181
182
183 # 11.3 Postfix Expressions
184 # RULE: LeftHandSideExpression always ends up in R0 (Let see if this would work)
185 PostfixOperator                                 ::= '++' | '--'
186 PostfixExpressionOp                     ::= <:LeftHandSideExpression:> <:PostfixOperator:>
187 PostfixExpressionValOp                  ::= <:ValLeftHandSideExpression:>
188 PostfixExpression                               ::= <:PostfixExpressionOp:> |
189                                                                         <:PostfixExpressionValOp:> 
190
191 PrefixOperator                                  ::= <:PostfixOperator:>
192 PrefixExpressionOp                              ::= <:PrefixOperator:> <:LeftHandSideExpression:>
193 PrefixExpression                                ::= <:PrefixExpressionOp:>
194
195 # 11.4 Unary Operators
196 UnaryOperatorOpcode                             ::= '~' | '!' | ('+' - '++') | ('-' - '--') | 'delete' | 'void' | 'typeof'
197 UnaryOperator                           ::= <:UnaryOperatorOpcode:>
198 UnaryExpressionOp                       ::=     <S>? <:UnaryOperator:> <S>? <:UnaryExpression:>
199 UnaryExpression                         ::=     <:UnaryExpressionOp:> | <:PrefixExpression:> | <:PostfixExpression:>
200
201
202 # 11.5 Multiplicative Operators
203 MultiplicativeOperator                  ::= '*' | '/' | '%'
204 MultiplicativeExpressionOp              ::= <:MultiplicativeExpression:> <S>? <:MultiplicativeOperator:> <S>? <:UnaryExpression:>
205 MultiplicativeExpression                ::= <:MultiplicativeExpressionOp:> | 
206                                                                         <:UnaryExpression:>
207
208 # 11.6 Additive Operators
209 AdditiveOperator                                ::= '+' | '-'
210 AdditiveExpressionOp                    ::= <:AdditiveExpression:> <S>? <:AdditiveOperator:> <S>? <:MultiplicativeExpression:>
211 AdditiveExpression                              ::= <:AdditiveExpressionOp:> | 
212                                                                         <:MultiplicativeExpression:>
213
214
215 11.7 Bitwise Shift Operators
216 ShiftOperator                                   ::= '>>>' | '<<' | '>>'
217 ShiftExpressionOp                               ::= <:ShiftExpression:> <S>? <:ShiftOperator:> <S>? <:AdditiveExpression:>
218 ShiftExpression                                 ::= <:ShiftExpressionOp:> |
219                                                                 <:AdditiveExpression:> 
220
221
222 # 11.8 Relational Operators
223 RelationalOperator                              ::= '<=' | '>=' | '<' | '>' | 'instanceof'
224 RelationalExpressionOp                  ::= <:RelationalExpression:> <S>? <:RelationalOperator:> <S>? <:ShiftExpression:>
225 RelationalExpression                    ::= <:RelationalExpressionOp:> |
226                                                                 <:ShiftExpression:>
227
228 # 11.9 Equality Operators
229 EqualityOperator                                ::= '===' | '==' | '!==' | '!='
230 EqualityExpressionOp                    ::= <:EqualityExpression:> <S>? <:EqualityOperator:> <S>? <:RelationalExpression:> 
231 EqualityExpression                              ::= <:EqualityExpressionOp:> |
232                                                                 <:RelationalExpression:>
233
234 BitwiseANDOperator                              ::= '&' - '&&'
235 BitwiseANDOp                                    ::= <:BitwiseANDExpression:> <S>? <:BitwiseANDOperator:> <S>? <:EqualityExpression:>
236 BitwiseANDExpression                    ::= <:BitwiseANDOp:> |
237                                                                 <:EqualityExpression:>
238
239 BitwiseXOROperator                              ::= '^'
240 BitwiseXOROp                                    ::= <:BitwiseXORExpression:> <S>? <:BitwiseXOROperator:> <S>? <:BitwiseANDExpression:>
241 BitwiseXORExpression                    ::= <:BitwiseXOROp:> |
242                                                                 <:BitwiseANDExpression:>
243
244 BitwiseOROperator                               ::= '|' - '||'
245 BitwiseOROp                                             ::= <:BitwiseORExpression:> <S>? <:BitwiseOROperator:> <S>? <:BitwiseXORExpression:>
246 BitwiseORExpression                     ::= <:BitwiseOROp:> |
247                                                                 <:BitwiseXORExpression:>
248
249 # 11.11 Binary Logical Operators
250 LogicalANDOperator                              ::= '&&'
251 LogicalANDOp                                    ::= <:LogicalANDExpression:> <S>? <:LogicalANDOperator:>  <S>? <:BitwiseORExpression:>
252 LogicalANDExpression                    ::= <:LogicalANDOp:> |
253                                                                 <:BitwiseORExpression:>
254
255 LogicalOROperator                               ::= '||'
256 LogicalOROp                                             ::= <:LogicalORExpression:> <S>? <:LogicalOROperator:> <S>? <:LogicalANDExpression:>
257 LogicalORExpression                     ::= <:LogicalOROp:> |
258                                                                 <:LogicalANDExpression:>
259
260
261 # 11.12 Conditional Operator ( ? : )
262 AssignmentExpressionIfTrueOp            ::= <:AssignmentExpression:>
263 AssignmentExpressionIfFalseOp           ::= <:AssignmentExpression:>
264 QuestionMarkOp                                          ::= '?'
265 ConditionalExpression                           ::= <:LogicalORExpression:> (<S>? <:QuestionMarkOp:> <S>? <:AssignmentExpressionIfTrueOp:> <S>? ':' <S>? <:AssignmentExpressionIfFalseOp:>)?
266
267 # 11.13 Assignment Operators
268 LeftHandSideExpressionPush              ::= <:LeftHandSideExpression:>
269 IdentifierAddressPush                   ::= <:Identifier:>
270 AssignmentExpressionOp                  ::= <:LeftHandSideExpressionPush:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpression:>
271 AssignmentExpression                    ::= <:AssignmentExpressionOp:> | 
272                                                                         <:ConditionalExpression:>
273
274 AssignmentExpressionNoIn                ::= <:LeftHandSideExpression:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpressionNoIn:> | <:ConditionalExpressionNoIn:>
275 AssignmentOperator                              ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
276
277
278 # 11.14 Comma Operator  ( , )
279 Expression              ::= <:AssignmentExpression:> ( <S>? ',' <S>? <:AssignmentExpression:> )*
280 ExpressionNoIn          ::= <:AssignmentExpressionNoIn:> ( <S>? ',' <S>? <:AssignmentExpressionNoIn:> )*
281
282
283 # 12 Statements
284 Statement                                               ::= <:BreakStatement:> |
285                                                                         <:ContinueStatement:> |
286                                                                         <:Block:> |
287                                                                 <:Comment:> |
288                                                                 <:VariableStatement:> |
289                                                                 <:EmptyStatement:> |
290                                                                 <:ExpressionStatement:> |
291                                                                 <:IfStatement:> |
292                                                                 <:IterationStatement:> |
293                                                                 <:ContinueStatement:> |
294                                                                 <:BreakStatement:> |
295                                                                 <:ReturnStatement:> |
296                                                                 <:ImportStatement:> |
297                                                                 <:WithStatement:> |
298                                                                 <:LabelledStatement:> |
299                                                                 <:SwitchStatement:> |
300                                                                 <:ThrowStatement:> |
301                                                                 <:TryStatement:> |
302                                                                 <:DebuggerStatement:>
303
304 # 12.1 Block
305 BlockBegin                                                      ::= <S>? '{' <S>?
306 BlockEnd                                                        ::= <S>? '}' <S>?
307 Block                                                           ::= <:BlockBegin:> <:StatementList:>? <:BlockEnd:>
308 StatementList                                           ::= (<S>? <:Statement:>)+
309
310 # 12.2 Variable Statement
311 VariableStatement                                       ::= 'var' <S>? <:VariableDeclarationList:> <:SC:>
312 VariableDeclarationList                         ::= <:VariableDeclaration:> (<:COMMA:> <:VariableDeclaration:> )*
313 VariableAllocate                                        ::= <:Identifier:>
314 VariableAllocateAndInit                         ::= <:Identifier:>
315 VariableDeclaration                                     ::= <:VariableAllocateAndInit:> <:Initialiser:> | <:VariableAllocate:>
316 Initialiser                                                     ::= <:EQ:> <:AssignmentExpression:>
317
318
319 # 12.3 Empty Statement
320 EmptyStatement                                          ::= <:SC:>
321
322 # 12.4 Expression Statement
323 ExpressionStatement                             ::= (<:Expression:> - ('function' | '{')) <:SC:>
324
325
326 # 12.5 The if Statement
327
328 ElseOp                                                          ::= 'else'
329 IfConditionOp                                           ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'
330 IfOp                                                            ::= <:IfConditionOp:> <S>? <:Statement:>
331 IfElseOp                                                        ::= <:IfConditionOp:> <S>? <:Statement:> <S>? <:ElseOp:> <S>? <:Statement:>
332
333 IfStatement                                                     ::= <:IfElseOp:> |
334                                                                                 <:IfOp:>
335
336 # 12.6 Iteration Statements
337 # 12.6a Iteration do ... while() 
338 WhileKeyword                                            ::= 'while'
339 WhileExpression                                         ::= <:WhileKeyword:> <S>? '(' <S>? <:Expression:> <S>? ')'
340 DoKeyword                                                       ::= 'do'
341 IterationDo                                                     ::= <:DoKeyword:> <S>? <:Statement:> <S>? <:WhileExpression:> (<S>? ';')
342
343 # 12.6b Iteration while()
344 WhileConditionOp                                        ::= 'while' <S>? '(' <S>? <:Expression:> <S>? ')'
345 IterationWhileOp                                        ::= <:WhileConditionOp:> <S>? <:Statement:>
346
347 # 12.6c Iteration for ( ; ; )
348 ForKeyword                                                      ::= 'for'
349 ExpressionNoIn                                          ::= <:Expression:>
350 ForExpressionInitOp                                     ::= ('var' <S>? <:VariableDeclarationList:>) | <:ExpressionNoIn:>
351 ForExpressionCompareOp                          ::= <:Expression:>
352 ForExpressionIncrementOp                        ::= <:Expression:>
353
354 # The following & expression is done in order to swap the places of the code generated for the comparison and increment.
355 # This is done by selectively turning on/off callbacks in both statement so that the final result appears as if the
356 # <:ForExpressionCompareOp:> <:ForExpressionIncrementOp:> appear in the opposite order.
357 ForIterationStatementOp                         ::= <:ForKeyword:> <S>? '(' <S>? <:ForExpressionInitOp:>? <S>? ';' <S>? <ForExpressionCompareOp>? <S>? ';' <S>? <:ForExpressionIncrementOp:>? <S>? ')' &
358                                                                                 <ForKeyword> <S>? '(' <S>? <ForExpressionInitOp>? <S>? ';' <S>? <:ForExpressionCompareOp:>? <S>? ';' <S>? <ForExpressionIncrementOp>? <S>? ')'
359 IterationForOp                                          ::= <:ForIterationStatementOp:> <S>? <:Statement:>
360
361
362 IterationStatement                                      ::= <:IterationWhileOp:> |
363                                                                                 <:IterationForOp:> |
364                                                                         <:IterationDo:>
365
366 # 12.9 The return Statement
367 ReturnOp                                                ::= ('return' - 'return' <:IdentifierPart:>) <WhiteSpace>* <:AssignmentExpression:>? (<S>? ';')
368 ReturnStatement                                 ::= <:ReturnOp:>
369
370 # The Break Statement
371 BreakOp                                                 ::= 'break' - 'break' <:IdentifierPart:>
372 BreakStatement                                  ::= <S>? <:BreakOp:> <:SC:>
373
374 # The Continue Statement
375 ContinueOp                                              ::= 'continue' - 'continue' <:IdentifierPart:>
376 ContinueStatement                               ::= <S>? <:ContinueOp:> <:SC:>
377
378
379 # 13 Function Definition
380 FunctionName                                            ::= <:Identifier:>
381 FunctionDefinition                                      ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionName:><S>?'('<S>?<:FormalParameterList:>?<S>?')'
382 FunctionDeclaration                                     ::= <:FunctionDefinition:><S>?'{'<S>?<:FunctionBody:>?<S>?'}'
383 FunctionExpression                                      ::= ('function' - 'function'<IdentifierPart>)<S>?<:FunctionName:>?<S>?'('<S>?<:FormalParameterList:>?<S>?')'<S>?'{'<S>?<:FunctionBody:>?<S>?'}'
384 FunctionParameter                                       ::= <:Identifier:>
385 FormalParameterList                             ::= <:FunctionParameter:> ( <S>? ',' <S>? <:FunctionParameter:> )*
386 FunctionBody                                            ::= <:SourceElements:>
387
388
389 # 14 Program
390 SourceElements                                  ::= (<S>? <:SourceElement:>)+
391 SourceElement                                           ::= <:FunctionDeclaration:> |
392                                                                         <:Statement:>
393 Program                                                 ::= <:SourceElements:>
394 # The root rule, it is anonymous
395 <:Program:>
396         
397