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