RPA Toolkit
3677984dec7b8833443d02831755b05798227df0
[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 ValPrimaryExpression                    ::= 'this' | 
123                                                                         <:BracketExpressionOp:> |
124                                                                 <:LiteralOp:> |
125                                                                 (<;SwiIdExist;> & <:SwiId:>) |
126                                                                 <:ValIdentifierOp:>
127
128
129
130 # The next line is mine
131 IdentifierOp                                    ::= <:Identifier:> 
132 ValIdentifierOp                                 ::= <:Identifier:> 
133 SwiId                                                   ::= <:Identifier:> 
134 SwiIdExist                                              ::= <SwiId> 
135
136
137 ArrayLiteral                                    ::= '[' <S>? <:Elision:>? <S>? ']' |
138                                                                 '[' <S>? <:ElementList:> <S>? ']' |
139                                                                 '[' <S>? <:ElementList:> <S>? ',' <S>? <:Elision:> <S>? ']'
140 ElementList                                             ::= <:Elision:>? <S>? <:AssignmentExpression:> (<S>? ',' <S>? <:Elision:>? <S>? <:AssignmentExpression:> )*
141 Elision                                                 ::= ',' <S>? <:Elision:> | <S>? ','
142
143
144 # 11.2 Left-Hand-Side Expressions
145 NewKeyword                                              ::= 'new' - 'new' <IdentifierPart>
146
147 MemberExpressionIndexBaseOp             ::= <:MemberExpression:>
148 MemberExpressionIndexOp                 ::= <:MemberExpressionIndexBaseOp:> <S>? '[' <:S:>? <:Expression:> <:S:>? ']'
149 MemberExpression                                ::= <:MemberExpressionIndexOp:>  |
150                                                                         <:MemberExpression:> '.' <:IdentifierName:> |
151                                                                         <:NewKeyword:> <S>? <:MemberExpression:> <S>? <:ArgumentsOp:> |
152                                                                         <:FunctionExpression:> |
153                                                                         <:PrimaryExpression:>
154
155
156 NewExpression                                   ::= <:NewArrayExpression:> |
157                                                                         <:NewKeyword:> <S>? <:NewExpression:> |
158                                                                         <:MemberExpression:>
159
160
161 FunctionCallName                                ::= <:CallExpression:> | <:MemberExpression:>
162 CallExpressionOp                                ::= <:FunctionCallName:> <S>? <:ArgumentsOp:>
163 CallExpressionIndexBaseOp               ::= <:CallExpression:>
164 CallExpressionIndexOp                   ::= <:CallExpressionIndexBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
165
166 CallExpression                                  ::= <:CallExpressionIndexOp:> |
167                                                                         <:CallExpression:> '.' <:IdentifierName:> |
168                                                                         <:CallExpressionOp:>
169
170 ArgumentsOp                                             ::= '(' <S>? ')' |
171                                                                 '(' <S>? <:ArgumentList:> <S>? ')'
172 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:AssignmentExpression:> |
173                                                                         <:AssignmentExpression:>
174
175 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:FunctionCallParameter:> |
176                                                                         <:FunctionCallParameter:>
177 FunctionCallParameter                   ::= <:AssignmentExpression:>
178                                                                         
179 LeftHandSideExpression                  ::= <:CallExpression:> | <:NewExpression:>
180
181
182
183 # 11.2a Left-Hand-Side Expressions
184 ValMemberExpressionIndexBaseOp  ::= <:ValMemberExpression:>
185 ValMemberExpressionIndexOp              ::= <:ValMemberExpressionIndexBaseOp:> <S>? '[' <:S:>? <:Expression:> <:S:>? ']'
186 ValMemberExpression                             ::= <:ValMemberExpressionIndexOp:>  |
187                                                                         <:ValMemberExpression:> '.' <:IdentifierName:> |
188                                                                         <:NewKeyword:> <S>? <:ValMemberExpression:> <S>? <:ArgumentsOp:> |
189                                                                         <:ValFunctionExpression:> |
190                                                                         <:ValPrimaryExpression:>
191
192
193 ValNewExpression                                ::= <:NewArrayExpression:> |
194                                                                         <:NewKeyword:> <S>? <:ValNewExpression:> |
195                                                                         <:ValMemberExpression:>
196
197
198 ValFunctionCallName                             ::= <:ValCallExpression:> | <:ValMemberExpression:>
199 ValCallExpressionOp                             ::= <:ValFunctionCallName:> <S>? <:ArgumentsOp:>
200 ValCallExpressionIndexBaseOp    ::= <:ValCallExpression:>
201 ValCallExpressionIndexOp                ::= <:ValCallExpressionIndexBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
202
203 ValCallExpression                               ::= <:ValCallExpressionIndexOp:> |
204                                                                         <:ValCallExpression:> '.' <:IdentifierName:> |
205                                                                         <:ValCallExpressionOp:>
206                 
207 ValLeftHandSideExpression               ::= <:ValCallExpression:> | <:ValNewExpression:>
208
209
210 # 11.3 Postfix Expressions
211 # RULE: LeftHandSideExpression always ends up in R0 (Let see if this would work)
212 PostfixOperator                                 ::= '++' | '--'
213 PostfixExpressionOp                     ::= <:LeftHandSideExpression:> <:PostfixOperator:>
214 PostfixExpressionValOp                  ::= <:ValLeftHandSideExpression:>
215 PostfixExpression                               ::= <:PostfixExpressionOp:> |
216                                                                         <:PostfixExpressionValOp:> 
217
218 PrefixOperator                                  ::= <:PostfixOperator:>
219 PrefixExpressionOp                              ::= <:PrefixOperator:> <:LeftHandSideExpression:>
220 PrefixExpression                                ::= <:PrefixExpressionOp:>
221
222 # 11.4 Unary Operators
223 UnaryOperatorOpcode                             ::= '~' | '!' | ('+' - '++') | ('-' - '--') | 'delete' | 'void' | 'typeof'
224 UnaryOperator                           ::= <:UnaryOperatorOpcode:>
225 UnaryExpressionOp                       ::=     <S>? <:UnaryOperator:> <S>? <:UnaryExpression:>
226 UnaryExpression                         ::=     <:UnaryExpressionOp:> | <:PrefixExpression:> | <:PostfixExpression:>
227
228
229 # 11.5 Multiplicative Operators
230 MultiplicativeOperator                  ::= '*' | '/' | '%'
231 MultiplicativeExpressionOp              ::= <:MultiplicativeExpression:> <S>? <:MultiplicativeOperator:> <S>? <:UnaryExpression:>
232 MultiplicativeExpression                ::= <:MultiplicativeExpressionOp:> | 
233                                                                         <:UnaryExpression:>
234
235 # 11.6 Additive Operators
236 AdditiveOperator                                ::= '+' | '-'
237 AdditiveExpressionOp                    ::= <:AdditiveExpression:> <S>? <:AdditiveOperator:> <S>? <:MultiplicativeExpression:>
238 AdditiveExpression                              ::= <:AdditiveExpressionOp:> | 
239                                                                         <:MultiplicativeExpression:>
240
241
242 11.7 Bitwise Shift Operators
243 ShiftOperator                                   ::= '>>>' | '<<' | '>>'
244 ShiftExpressionOp                               ::= <:ShiftExpression:> <S>? <:ShiftOperator:> <S>? <:AdditiveExpression:>
245 ShiftExpression                                 ::= <:ShiftExpressionOp:> |
246                                                                 <:AdditiveExpression:> 
247
248
249 # 11.8 Relational Operators
250 RelationalOperator                              ::= '<=' | '>=' | '<' | '>' | 'instanceof'
251 RelationalExpressionOp                  ::= <:RelationalExpression:> <S>? <:RelationalOperator:> <S>? <:ShiftExpression:>
252 RelationalExpression                    ::= <:RelationalExpressionOp:> |
253                                                                 <:ShiftExpression:>
254
255 # 11.9 Equality Operators
256 EqualityOperator                                ::= '===' | '==' | '!==' | '!='
257 EqualityExpressionOp                    ::= <:EqualityExpression:> <S>? <:EqualityOperator:> <S>? <:RelationalExpression:> 
258 EqualityExpression                              ::= <:EqualityExpressionOp:> |
259                                                                 <:RelationalExpression:>
260
261 BitwiseANDOperator                              ::= '&' - '&&'
262 BitwiseANDOp                                    ::= <:BitwiseANDExpression:> <S>? <:BitwiseANDOperator:> <S>? <:EqualityExpression:>
263 BitwiseANDExpression                    ::= <:BitwiseANDOp:> |
264                                                                 <:EqualityExpression:>
265
266 BitwiseXOROperator                              ::= '^'
267 BitwiseXOROp                                    ::= <:BitwiseXORExpression:> <S>? <:BitwiseXOROperator:> <S>? <:BitwiseANDExpression:>
268 BitwiseXORExpression                    ::= <:BitwiseXOROp:> |
269                                                                 <:BitwiseANDExpression:>
270
271 BitwiseOROperator                               ::= '|' - '||'
272 BitwiseOROp                                             ::= <:BitwiseORExpression:> <S>? <:BitwiseOROperator:> <S>? <:BitwiseXORExpression:>
273 BitwiseORExpression                     ::= <:BitwiseOROp:> |
274                                                                 <:BitwiseXORExpression:>
275
276 # 11.11 Binary Logical Operators
277 LogicalANDOperator                              ::= '&&'
278 LogicalANDOp                                    ::= <:LogicalANDExpression:> <S>? <:LogicalANDOperator:>  <S>? <:BitwiseORExpression:>
279 LogicalANDExpression                    ::= <:LogicalANDOp:> |
280                                                                 <:BitwiseORExpression:>
281
282 LogicalOROperator                               ::= '||'
283 LogicalOROp                                             ::= <:LogicalORExpression:> <S>? <:LogicalOROperator:> <S>? <:LogicalANDExpression:>
284 LogicalORExpression                     ::= <:LogicalOROp:> |
285                                                                 <:LogicalANDExpression:>
286
287
288 # 12.6 Iteration Statements
289 WhileKeyword                                            ::= 'while'
290 WhileExpression                                         ::= <:WhileKeyword:> <S>? '(' <S>? <:Expression:> <S>? ')'
291 DoKeyword                                                       ::= 'do'
292 IterationDo                                                     ::= <:DoKeyword:> <S>? <:Statement:> <S>? <:WhileExpression:> (<S>? ';')
293 WhileConditionOp                                        ::= 'while' <S>? '(' <S>? <:Expression:> <S>? ')'
294 IterationWhileOp                                        ::= <:WhileConditionOp:> <S>? <:Statement:>
295 IterationStatement                                      ::= <:IterationWhileOp:> |
296                                                                         <:IterationDo:>
297
298 # 11.12 Conditional Operator ( ? : )
299 #ConditionalExpression                          ::= <:LogicalORExpression:> ( <S>? '?' <S>? <:AssignmentExpression:> <S>? ':' <S>? <:AssignmentExpression:> )?
300 #ConditionalExpressionNoIn                      ::=<:LogicalORExpressionNoIn:> ( <S>? '?' <S>? <:AssignmentExpression:> <S>? ':' <S>? <:AssignmentExpressionNoIn:> )?
301 #
302
303 AssignmentExpressionTrueOp                      ::= <:AssignmentExpression:>
304 AssignmentExpressionFalseOp                     ::= <:AssignmentExpression:>
305 ConditionalExpressionActionOp           ::= <S>? '?' <S>? <:AssignmentExpressionTrueOp:> <S>? ':' <S>? <:AssignmentExpressionFalseOp:> 
306 ConditionalExpression                           ::= <:LogicalORExpression:> <:ConditionalExpressionActionOp:>?
307
308 # 11.13 Assignment Operators
309 LeftHandSideExpressionPush              ::= <:LeftHandSideExpression:>
310 IdentifierAddressPush                   ::= <:Identifier:>
311 AssignmentExpressionOp                  ::= <:LeftHandSideExpressionPush:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpression:>
312 AssignmentExpression                    ::= <:AssignmentExpressionOp:> | 
313                                                                         <:ConditionalExpression:>
314
315 AssignmentExpressionNoIn                ::= <:LeftHandSideExpression:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpressionNoIn:> | <:ConditionalExpressionNoIn:>
316 AssignmentOperator                              ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
317
318
319 # 11.14 Comma Operator  ( , )
320 Expression              ::= <:AssignmentExpression:> ( <S>? ',' <S>? <:AssignmentExpression:> )*
321 ExpressionNoIn          ::= <:AssignmentExpressionNoIn:> ( <S>? ',' <S>? <:AssignmentExpressionNoIn:> )*
322
323 #Print statement;
324 PrintOp                                                 ::= '%'print'%'
325
326 # 12 Statements
327 Statement                                               ::= <:PrintOp:> |
328                                                                         <:Block:> |
329                                                                 <:Comment:> |
330                                                                 <:VariableStatement:> |
331                                                                 <:EmptyStatement:> |
332                                                                 <:ExpressionStatement:> |
333                                                                 <:IfStatement:> |
334                                                                 <:IterationStatement:> |
335                                                                 <:ContinueStatement:> |
336                                                                 <:BreakStatement:> |
337                                                                 <:ReturnStatement:> |
338                                                                 <:ImportStatement:> |
339                                                                 <:WithStatement:> |
340                                                                 <:LabelledStatement:> |
341                                                                 <:SwitchStatement:> |
342                                                                 <:ThrowStatement:> |
343                                                                 <:TryStatement:> |
344                                                                 <:DebuggerStatement:>
345
346 # 12.1 Block
347 BlockBegin                                                      ::= <S>? '{' <S>?
348 BlockEnd                                                        ::= <S>? '}' <S>?
349 Block                                                           ::= <:BlockBegin:> <:StatementList:>? <:BlockEnd:>
350 StatementList                                           ::= (<S>? <:Statement:>)+
351
352 # 12.2 Variable Statement
353 VariableStatement                                       ::= 'var' <S>? <:VariableDeclarationList:> <:SC:>
354 VariableDeclarationList                         ::= <:VariableDeclaration:> (<:COMMA:> <:VariableDeclaration:> )*
355 VariableAllocate                                        ::= <:Identifier:>
356 VariableAllocateAndInit                         ::= <:Identifier:>
357 VariableDeclaration                                     ::= <:VariableAllocateAndInit:> <:Initialiser:> | <:VariableAllocate:>
358 Initialiser                                                     ::= <:EQ:> <:AssignmentExpression:>
359
360
361 # 12.3 Empty Statement
362 EmptyStatement                                          ::= <:SC:>
363
364 # 12.4 Expression Statement
365 ExpressionStatement                             ::= (<:Expression:> - ('function' | '{')) <:SC:>
366
367
368 # 12.5 The if Statement
369
370 ElseOp                                                          ::= 'else'
371 IfConditionOp                                           ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'
372 IfOp                                                            ::= <:IfConditionOp:> <S>? <:Statement:>
373 IfElseOp                                                        ::= <:IfConditionOp:> <S>? <:Statement:> <S>? <:ElseOp:> <S>? <:Statement:>
374
375 IfStatement                                                     ::= <:IfElseOp:> |
376                                                                                 <:IfOp:>
377
378 #IfStatement                                                    ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'<S>? <:Statement:> <S>? 'else' <S>? <:Statement:> |
379 #                                                                       'if' <S>? '(' <S>? <:Expression:> <S>? ')'<S>? <:Statement:> 
380
381
382 # 12.9 The return Statement
383 ReturnOp                                                ::= ('return' - 'return' <:IdentifierPart:>) <WhiteSpace>* <:AssignmentExpression:>? (<S>? ';')
384 ReturnStatement                                 ::= <:ReturnOp:>
385
386
387 # 13 Function Definition
388 FunctionName                                            ::= <:Identifier:>
389 FunctionDefinition                                      ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionName:><S>?'('<S>?<:FormalParameterList:>?<S>?')'
390 FunctionDeclaration                                     ::= <:FunctionDefinition:><S>?'{'<S>?<:FunctionBody:>?<S>?'}'
391 FunctionExpression                                      ::= ('function' - 'function'<IdentifierPart>)<S>?<:FunctionName:>?<S>?'('<S>?<:FormalParameterList:>?<S>?')'<S>?'{'<S>?<:FunctionBody:>?<S>?'}'
392 FunctionParameter                                       ::= <:Identifier:>
393 FormalParameterList                             ::= <:FunctionParameter:> ( <S>? ',' <S>? <:FunctionParameter:> )*
394 FunctionBody                                            ::= <:SourceElements:>
395
396
397 # 14 Program
398 SourceElements                                  ::= (<S>? <:SourceElement:>)+
399 SourceElement                                           ::= <:FunctionDeclaration:> |
400                                                                         <:Statement:>
401 Program                                                 ::= <:SourceElements:>
402 # The root rule, it is anonymous
403 <:Program:>
404         
405