RPA Toolkit
8ed79e111337e9e43573f3d805a5258f204564b8
[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 # 7.8.3 Numeric Literals
81
82 NumericLiteral                                  ::= <:HexIntegerLiteral:> | <:DecimalNonIntegerLiteral:> | <:DecimalIntegerLiteral:>
83 DecimalNonIntegerLiteral                ::= ('0' | <:NonZeroDigit:> <DecimalDigits>?) '.' <DecimalDigits>? <:ExponentPart:>? |
84                                                                 '.' <:DecimalDigits:> <:ExponentPart:>? 
85 DecimalIntegerLiteral                   ::= '0' | <:NonZeroDigit:> <:DecimalDigits:>? <:ExponentPart:>?
86 DecimalDigits                                   ::= <:DecimalDigit:>+
87 DecimalDigit                                    ::= [0-9]
88 NonZeroDigit                                    ::= [1-9]
89 ExponentPart                                    ::= <:ExponentIndicator:> <:SignedInteger:>
90 ExponentIndicator                               ::= [eE]
91 SignedInteger                                   ::= '-' <:DecimalDigits:> |
92                                                                 '+' <:DecimalDigits:> |
93                                                                 <:DecimalDigits:>
94 HexIntegerLiteral                               ::= '0' [xX] <:HexDigit:>+
95 HexDigit                                                ::= [0-9a-fA-F]
96
97 # 7.8.4 String Literals
98 StringLiteral                                   ::= '\"' <:DoubleStringCharacters:>? '\"' |
99                                                                 ['] <:SingleStringCharacters:>? [']
100
101 DoubleStringCharacters                  ::= <:DoubleStringCharacter:>+
102 SingleStringCharacters                  ::= <:SingleStringCharacter:>+
103
104 DoubleStringCharacter                   ::= '\\' <:EscapeSequence:> |
105                                                                 <:LineContinuation:> |
106                                                                 <:SourceCharacter:> - ('\"' | '\\' | <:LineTerminator:>)
107
108 SingleStringCharacter                   ::= '\\' <:EscapeSequence:> |
109                                                                 <:LineContinuation:> |
110                                                                 <:SourceCharacter:> - (['] | '\\' | <:LineTerminator:>)
111
112 PrimaryExpression                               ::= 'this' | 
113                                                                 '(' <S>? <:Expression:> <S>? ')' |
114                                                                 <:Literal:> |
115                                                                 (<;SwiIdExist;> & <:SwiId:>) |
116                                                                 <:IdentifierOp:>
117                                                                 
118
119 # The next line is mine
120 IdentifierOp                                    ::= <:Identifier:> 
121 SwiId                                                   ::= <:Identifier:> 
122 SwiIdExist                                              ::= <SwiId> 
123
124
125 ArrayLiteral                                    ::= '[' <S>? <:Elision:>? <S>? ']' |
126                                                                 '[' <S>? <:ElementList:> <S>? ']' |
127                                                                 '[' <S>? <:ElementList:> <S>? ',' <S>? <:Elision:> <S>? ']'
128 ElementList                                             ::= <:Elision:>? <S>? <:AssignmentExpression:> (<S>? ',' <S>? <:Elision:>? <S>? <:AssignmentExpression:> )*
129 Elision                                                 ::= ',' <S>? <:Elision:> | <S>? ','
130
131
132 # 11.2 Left-Hand-Side Expressions
133 NewKeyword                                              ::= 'new' - 'new' <IdentifierPart>
134
135 MemberExpressionIndexBaseOp             ::= <:MemberExpression:>
136 MemberExpressionIndexOp                 ::= <:MemberExpressionIndexBaseOp:> <S>? '[' <:S:>? <:Expression:> <:S:>? ']'
137 MemberExpression                                ::= <:MemberExpressionIndexOp:>  |
138                                                                         <:MemberExpression:> '.' <:IdentifierName:> |
139                                                                         <:NewKeyword:> <S>? <:MemberExpression:> <S>? <:Arguments:> |
140                                                                         <:FunctionExpression:> |
141                                                                         <:PrimaryExpression:>
142
143
144 NewExpression                                   ::= <:NewArrayExpression:> |
145                                                                         <:NewKeyword:> <S>? <:NewExpression:> |
146                                                                         <:MemberExpression:>
147
148
149 FunctionCallName                                ::= <:CallExpression:> | <:MemberExpression:>
150 CallExpressionOp                                ::= <:FunctionCallName:> <S>? <:Arguments:>
151 CallExpressionIndexBaseOp               ::= <:CallExpression:>
152 CallExpressionIndexOp                   ::= <:CallExpressionIndexBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
153
154 CallExpression                                  ::= <:CallExpressionIndexOp:> |
155                                                                         <:CallExpression:> '.' <:IdentifierName:> |
156                                                                         <:CallExpressionOp:>
157
158 Arguments                                               ::= '(' <S>? ')' |
159                                                                 '(' <S>? <:ArgumentList:> <S>? ')'
160 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:AssignmentExpression:> |
161                                                                         <:AssignmentExpression:>
162 LeftHandSideExpression                  ::= <:CallExpression:> | <:NewExpression:>
163
164 # The next lines are mine
165 LeftHandSideExpressionDeref             ::= <:LeftHandSideExpression:>
166 LeftHandSideExpressionValue             ::= <:NewArrayExpression:> |
167                                                                         <:LeftHandSideExpressionDeref:> |
168                                                                         <:Literal:>
169 ArgumentList                                    ::= <:ArgumentList:> <S>? ',' <S>? <:FunctionCallParameter:> |
170                                                                         <:FunctionCallParameter:>
171 FunctionCallParameter                   ::= <:AssignmentExpression:>
172
173
174
175 # 11.3 Postfix Expressions
176 # RULE: LeftHandSideExpression always ends up in R0 (Let see if this would work)
177 PostfixOperator                                 ::= '++' | '--'
178 PostfixExpressionOp                     ::= <:LeftHandSideExpression:> <:PostfixOperator:>
179 PostfixExpression                               ::= <:PostfixExpressionOp:> |
180                                                                         <:LeftHandSideExpression:>
181
182 LiteralPushOp                                   ::= <:Literal:>
183 IdentifierValueOp                               ::= <:Identifier:> - (<:Identifier:> <S>? ('.' | '[' | '++' | '--'))
184
185 # 11.4 Unary Operators
186 UnaryOperator                           ::= 'delete' | 'void' | 'typeof' | '++' | '--' | '+' | '-' | '~' | '!'
187 UnaryExpressionOp                       ::=     <S>? <:UnaryOperator:> <S>? <:UnaryExpression:>
188 UnaryExpression                         ::=     <:UnaryExpressionOp:> | (<:LiteralPushOp:> | <:PostfixExpression:>)
189
190
191 # 11.5 Multiplicative Operators
192 MultiplicativeOperator                  ::= '*' | '/' | '%' # Not used
193 MultiplicativeExpressionOp              ::= <:MultiplicativeExpression:> <S>? <:MultiplicativeOperator:> <S>? <:UnaryExpression:>
194 MultiplicativeExpression                ::= <:MultiplicativeExpressionOp:> | 
195                                                                         <:UnaryExpression:>
196
197 # 11.6 Additive Operators
198 AdditiveOperator                                ::= '+' | '-'
199 AdditiveExpressionOp                    ::= <:AdditiveExpression:> <S>? <:AdditiveOperator:> <S>? <:MultiplicativeExpression:>
200 AdditiveExpression                              ::= <:AdditiveExpressionOp:> | 
201                                                                         <:MultiplicativeExpression:>
202
203
204 11.7 Bitwise Shift Operators
205 ShiftOperator                                   ::= '>>>' | '<<' | '>>'
206 ShiftExpressionOp                               ::= <:ShiftExpression:> <S>? <:ShiftOperator:> <S>? <:AdditiveExpression:>
207 ShiftExpression                                 ::= <:ShiftExpressionOp:> |
208                                                                 <:AdditiveExpression:> 
209
210
211 # 11.8 Relational Operators
212 RelationalOperator                              ::= '<=' | '>=' | '<' | '>' | 'instanceof'
213 RelationalExpressionOp                  ::= <:RelationalExpression:> <S>? <:RelationalOperator:> <S>? <:ShiftExpression:>
214 RelationalExpression                    ::= <:RelationalExpressionOp:> |
215                                                                 <:ShiftExpression:>
216
217 # 11.9 Equality Operators
218 EqualityOperator                                ::= '===' | '==' | '!==' | '!='
219 EqualityExpressionOp                    ::= <:EqualityExpression:> <S>? <:EqualityOperator:> <S>? <:RelationalExpression:> 
220 EqualityExpression                              ::= <:EqualityExpressionOp:> |
221                                                                 <:RelationalExpression:>
222
223 BitwiseANDOperator                              ::= '&' - '&&'
224 BitwiseANDOp                                    ::= <:BitwiseANDExpression:> <S>? <:BitwiseANDOperator:> <S>? <:EqualityExpression:>
225 BitwiseANDExpression                    ::= <:BitwiseANDOp:> |
226                                                                 <:EqualityExpression:>
227
228 BitwiseXOROperator                              ::= '^'
229 BitwiseXOROp                                    ::= <:BitwiseXORExpression:> <S>? <:BitwiseXOROperator:> <S>? <:BitwiseANDExpression:>
230 BitwiseXORExpression                    ::= <:BitwiseXOROp:> |
231                                                                 <:BitwiseANDExpression:>
232
233 BitwiseOROperator                               ::= '|' - '||'
234 BitwiseOROp                                             ::= <:BitwiseORExpression:> <S>? <:BitwiseOROperator:> <S>? <:BitwiseXORExpression:>
235 BitwiseORExpression                     ::= <:BitwiseOROp:> |
236                                                                 <:BitwiseXORExpression:>
237
238 # 11.11 Binary Logical Operators
239 LogicalANDOperator                      ::= '&&'
240 LogicalANDOp                                    ::= <:LogicalANDExpression:> <S>? <:LogicalANDOperator:>  <S>? <:BitwiseORExpression:>
241 LogicalANDExpression                    ::= <:LogicalANDOp:> |
242                                                                 <:BitwiseORExpression:>
243
244 LogicalOROperator                               ::= '||'
245 LogicalOROp                                             ::= <:LogicalORExpression:> <S>? <:LogicalOROperator:> <S>? <:LogicalANDExpression:>
246 LogicalORExpression                     ::= <:LogicalOROp:> |
247                                                                 <:LogicalANDExpression:>
248
249
250 # 12.6 Iteration Statements
251 WhileKeyword                                            ::= 'while'
252 WhileExpression                                         ::= <:WhileKeyword:> <S>? '(' <S>? <:Expression:> <S>? ')'
253 IterationWhile                                          ::= <:WhileKeyword:> '(' <S>? <:Expression:> <S>? ')' <S>? <:Statement:>
254 DoKeyword                                                       ::= 'do'
255 IterationDo                                                     ::= <:DoKeyword:> <S>? <:Statement:> <S>? <:WhileExpression:> (<S>? ';')
256 IterationStatement                                      ::= <:IterationWhile:> |
257                                                                         <:IterationDo:>
258
259
260 ## 11.12 Conditional Operator ( ? : )
261 #ConditionalExpression                  ::= <:LogicalORExpression:> ( <S>? '?' <S>? <:AssignmentExpression:> <S>? ':' <S>? <:AssignmentExpression:> )?
262 #ValueOfExpression                              ::= <:NewArrayExpression:> |
263 #                                                                       <:Expression:>
264 ## 11.13 Assignment Operators
265 #ArrayElementAddress                    ::= <:IdentifierValue:> <:S:>? <:ArrayLiteral:>
266 #IdentifierAddress                              ::= <:Identifier:>
267 #Address                                                ::= <:ArrayElementAddress:> | <:IdentifierAddress:>
268 #IdentifierValue                                ::= <:Identifier:>
269 #AssignmetLHS                                   ::= <:LeftHandSideExpression:>
270 #AssignmentEq                                   ::= <:AssignmetLHS:> <:S:>? '=' <:S:>? <:AssignmentExpression:> 
271 #AssignmentAddEq                                ::= <:AssignmetLHS:> <:S:>? '+=' <:S:>? <:AssignmentExpression:> 
272 #AssignmentMulEq                                ::= <:AssignmetLHS:> <:S:>? '*=' <:S:>? <:AssignmentExpression:> 
273 #
274 #AssignmentExpression                   ::= <:AssignmentEq:> | 
275 #                                                                       <:AssignmentAddEq:> | 
276 #                                                                       <:AssignmentMulEq:> | 
277 #                                                                       <:CallExpression:> |
278 #                                                                       <:ValueOfExpression:>
279
280
281 # 11.12 Conditional Operator ( ? : )
282 #ConditionalExpression  ::= <:LogicalORExpression:> ( <S>? '?' <S>? <:AssignmentExpression:> <S>? ':' <S>? <:AssignmentExpression:> )?
283 #ConditionalExpressionNoIn::=<:LogicalORExpressionNoIn:> ( <S>? '?' <S>? <:AssignmentExpression:> <S>? ':' <S>? <:AssignmentExpressionNoIn:> )?
284 #
285 ConditionalExpression   ::= <:LogicalORExpression:>
286
287 # 11.13 Assignment Operators
288 LeftHandSideExpressionPush              ::= <:LeftHandSideExpression:>
289 AssignmentExpressionOp                  ::= <:LeftHandSideExpressionPush:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpression:>
290 AssignmentExpression                    ::= <:AssignmentExpressionOp:> | <:ConditionalExpression:>
291
292 AssignmentExpressionNoIn::= <:LeftHandSideExpression:> <S>? <:AssignmentOperator:> <S>? <:AssignmentExpressionNoIn:> | <:ConditionalExpressionNoIn:>
293 AssignmentOperator      ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|='
294
295
296 # 11.14 Comma Operator  ( , )
297 Expression              ::= <:AssignmentExpression:> ( <S>? ',' <S>? <:AssignmentExpression:> )*
298 ExpressionNoIn          ::= <:AssignmentExpressionNoIn:> ( <S>? ',' <S>? <:AssignmentExpressionNoIn:> )*
299
300
301 # 12 Statements
302 Statement                                               ::= <:Block:> |
303                                                                 <:Comment:> |
304                                                                 <:VariableStatement:> |
305                                                                 <:EmptyStatement:> |
306                                                                 <:ExpressionStatement:> |
307                                                                 <:IfStatement:> |
308                                                                 <:IterationStatement:> |
309                                                                 <:ContinueStatement:> |
310                                                                 <:BreakStatement:> |
311                                                                 <:ReturnStatement:> |
312                                                                 <:ImportStatement:> |
313                                                                 <:WithStatement:> |
314                                                                 <:LabelledStatement:> |
315                                                                 <:SwitchStatement:> |
316                                                                 <:ThrowStatement:> |
317                                                                 <:TryStatement:> |
318                                                                 <:DebuggerStatement:>
319
320 # 12.1 Block
321 BlockBegin                                                      ::= <S>? '{' <S>?
322 BlockEnd                                                        ::= <S>? '}' <S>?
323 Block                                                           ::= <:BlockBegin:> <:StatementList:>? <:BlockEnd:>
324 StatementList                                           ::= (<S>? <:Statement:>)+
325
326 # 12.2 Variable Statement
327 VariableStatement                                       ::= 'var' <S>? <:VariableDeclarationList:> <:SC:>
328 VariableDeclarationList                         ::= <:VariableDeclaration:> (<:COMMA:> <:VariableDeclaration:> )*
329 VariableAllocate                                        ::= <:Identifier:>
330 VariableAllocateAndInit                         ::= <:Identifier:>
331 VariableDeclaration                                     ::= <:VariableAllocateAndInit:> <:Initialiser:> | <:VariableAllocate:>
332 Initialiser                                                     ::= <:EQ:> <:AssignmentExpression:>
333
334
335 # 12.3 Empty Statement
336 EmptyStatement                                          ::= <:SC:>
337
338 # 12.4 Expression Statement
339 ExpressionStatement                             ::= (<:Expression:> - ('function' | '{')) <:SC:>
340
341
342 # 12.5 The if Statement
343
344 ElseOp                                                          ::= 'else'
345 IfConditionOp                                           ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'
346 IfOp                                                            ::= <:IfConditionOp:> <S>? <:Statement:>
347 IfElseOp                                                        ::= <:IfConditionOp:> <S>? <:Statement:> <S>? <:ElseOp:> <S>? <:Statement:>
348
349 IfStatement                                                     ::= <:IfElseOp:> |
350                                                                                 <:IfOp:>
351
352 #IfStatement                                                    ::= 'if' <S>? '(' <S>? <:Expression:> <S>? ')'<S>? <:Statement:> <S>? 'else' <S>? <:Statement:> |
353 #                                                                       'if' <S>? '(' <S>? <:Expression:> <S>? ')'<S>? <:Statement:> 
354
355
356 # 12.9 The return Statement
357 ReturnOp                                                ::= ('return' - 'return' <:IdentifierPart:>) <WhiteSpace>* <:AssignmentExpression:>? (<S>? ';')
358 ReturnStatement                                 ::= <:ReturnOp:>
359
360
361 # 13 Function Definition
362 FunctionName                                            ::= <:Identifier:>
363 FunctionDefinition                                      ::= ('function' - 'function' <IdentifierPart>)<S>?<:FunctionName:><S>?'('<S>?<:FormalParameterList:>?<S>?')'
364 FunctionDeclaration                                     ::= <:FunctionDefinition:><S>?'{'<S>?<:FunctionBody:>?<S>?'}'
365 FunctionExpression                                      ::= ('function' - 'function'<IdentifierPart>)<S>?<:FunctionName:>?<S>?'('<S>?<:FormalParameterList:>?<S>?')'<S>?'{'<S>?<:FunctionBody:>?<S>?'}'
366 FunctionParameter                                       ::= <:Identifier:>
367 FormalParameterList                             ::= <:FunctionParameter:> ( <S>? ',' <S>? <:FunctionParameter:> )*
368 FunctionBody                                            ::= <:SourceElements:>
369
370
371 # 14 Program
372 SourceElements                                  ::= (<S>? <:SourceElement:>)+
373 SourceElement                                           ::= <:FunctionDeclaration:> |
374                                                                         <:Statement:>
375 Program                                                 ::= <:SourceElements:>
376 ProgramInit                                             ::= <:SourceCharacter:>
377 # The root rule, it is anonymous
378 <:Program:>
379         
380