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