Removed modules/contrib/media module to allow update to the core media module
[yaffs-website] / vendor / nikic / php-parser / grammar / php5.y
1 %pure_parser
2 %expect 6
3
4 %tokens
5
6 %%
7
8 start:
9     top_statement_list                                      { $$ = $this->handleNamespaces($1); }
10 ;
11
12 top_statement_list_ex:
13       top_statement_list_ex top_statement                   { pushNormalizing($1, $2); }
14     | /* empty */                                           { init(); }
15 ;
16
17 top_statement_list:
18       top_statement_list_ex
19           { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
20             if ($nop !== null) { $1[] = $nop; } $$ = $1; }
21 ;
22
23 reserved_non_modifiers:
24       T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND
25     | T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE
26     | T_ENDWHILE | T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH
27     | T_FINALLY | T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
28     | T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT
29     | T_BREAK | T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
30     | T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_HALT_COMPILER
31 ;
32
33 semi_reserved:
34       reserved_non_modifiers
35     | T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
36 ;
37
38 identifier_ex:
39       T_STRING                                              { $$ = Node\Identifier[$1]; }
40     | semi_reserved                                         { $$ = Node\Identifier[$1]; }
41 ;
42
43 identifier:
44       T_STRING                                              { $$ = Node\Identifier[$1]; }
45 ;
46
47 reserved_non_modifiers_identifier:
48       reserved_non_modifiers                                { $$ = Node\Identifier[$1]; }
49 ;
50
51 namespace_name_parts:
52       T_STRING                                              { init($1); }
53     | namespace_name_parts T_NS_SEPARATOR T_STRING          { push($1, $3); }
54 ;
55
56 namespace_name:
57       namespace_name_parts                                  { $$ = Name[$1]; }
58 ;
59
60 plain_variable:
61       T_VARIABLE                                            { $$ = Expr\Variable[parseVar($1)]; }
62 ;
63
64 top_statement:
65       statement                                             { $$ = $1; }
66     | function_declaration_statement                        { $$ = $1; }
67     | class_declaration_statement                           { $$ = $1; }
68     | T_HALT_COMPILER
69           { $$ = Stmt\HaltCompiler[$this->lexer->handleHaltCompiler()]; }
70     | T_NAMESPACE namespace_name ';'
71           { $$ = Stmt\Namespace_[$2, null];
72             $$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON);
73             $this->checkNamespace($$); }
74     | T_NAMESPACE namespace_name '{' top_statement_list '}'
75           { $$ = Stmt\Namespace_[$2, $4];
76             $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
77             $this->checkNamespace($$); }
78     | T_NAMESPACE '{' top_statement_list '}'
79           { $$ = Stmt\Namespace_[null, $3];
80             $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
81             $this->checkNamespace($$); }
82     | T_USE use_declarations ';'                            { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; }
83     | T_USE use_type use_declarations ';'                   { $$ = Stmt\Use_[$3, $2]; }
84     | group_use_declaration ';'                             { $$ = $1; }
85     | T_CONST constant_declaration_list ';'                 { $$ = Stmt\Const_[$2]; }
86 ;
87
88 use_type:
89       T_FUNCTION                                            { $$ = Stmt\Use_::TYPE_FUNCTION; }
90     | T_CONST                                               { $$ = Stmt\Use_::TYPE_CONSTANT; }
91 ;
92
93 /* Using namespace_name_parts here to avoid s/r conflict on T_NS_SEPARATOR */
94 group_use_declaration:
95       T_USE use_type namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
96           { $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, $2]; }
97     | T_USE use_type T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
98           { $$ = Stmt\GroupUse[new Name($4, stackAttributes(#4)), $7, $2]; }
99     | T_USE namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
100           { $$ = Stmt\GroupUse[new Name($2, stackAttributes(#2)), $5, Stmt\Use_::TYPE_UNKNOWN]; }
101     | T_USE T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
102           { $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, Stmt\Use_::TYPE_UNKNOWN]; }
103 ;
104
105 unprefixed_use_declarations:
106       unprefixed_use_declarations ',' unprefixed_use_declaration
107           { push($1, $3); }
108     | unprefixed_use_declaration                            { init($1); }
109 ;
110
111 use_declarations:
112       use_declarations ',' use_declaration                  { push($1, $3); }
113     | use_declaration                                       { init($1); }
114 ;
115
116 inline_use_declarations:
117       inline_use_declarations ',' inline_use_declaration    { push($1, $3); }
118     | inline_use_declaration                                { init($1); }
119 ;
120
121 unprefixed_use_declaration:
122       namespace_name
123           { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
124     | namespace_name T_AS identifier
125           { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
126 ;
127
128 use_declaration:
129       unprefixed_use_declaration                            { $$ = $1; }
130     | T_NS_SEPARATOR unprefixed_use_declaration             { $$ = $2; }
131 ;
132
133 inline_use_declaration:
134       unprefixed_use_declaration                            { $$ = $1; $$->type = Stmt\Use_::TYPE_NORMAL; }
135     | use_type unprefixed_use_declaration                   { $$ = $2; $$->type = $1; }
136 ;
137
138 constant_declaration_list:
139       constant_declaration_list ',' constant_declaration    { push($1, $3); }
140     | constant_declaration                                  { init($1); }
141 ;
142
143 constant_declaration:
144     identifier '=' static_scalar                            { $$ = Node\Const_[$1, $3]; }
145 ;
146
147 class_const_list:
148       class_const_list ',' class_const                      { push($1, $3); }
149     | class_const                                           { init($1); }
150 ;
151
152 class_const:
153     identifier_ex '=' static_scalar                         { $$ = Node\Const_[$1, $3]; }
154 ;
155
156 inner_statement_list_ex:
157       inner_statement_list_ex inner_statement               { pushNormalizing($1, $2); }
158     | /* empty */                                           { init(); }
159 ;
160
161 inner_statement_list:
162       inner_statement_list_ex
163           { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
164             if ($nop !== null) { $1[] = $nop; } $$ = $1; }
165 ;
166
167 inner_statement:
168       statement                                             { $$ = $1; }
169     | function_declaration_statement                        { $$ = $1; }
170     | class_declaration_statement                           { $$ = $1; }
171     | T_HALT_COMPILER
172           { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); }
173 ;
174
175 non_empty_statement:
176       '{' inner_statement_list '}'
177     {
178         if ($2) {
179             $$ = $2; prependLeadingComments($$);
180         } else {
181             makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
182             if (null === $$) { $$ = array(); }
183         }
184     }
185     | T_IF parentheses_expr statement elseif_list else_single
186           { $$ = Stmt\If_[$2, ['stmts' => toArray($3), 'elseifs' => $4, 'else' => $5]]; }
187     | T_IF parentheses_expr ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
188           { $$ = Stmt\If_[$2, ['stmts' => $4, 'elseifs' => $5, 'else' => $6]]; }
189     | T_WHILE parentheses_expr while_statement              { $$ = Stmt\While_[$2, $3]; }
190     | T_DO statement T_WHILE parentheses_expr ';'           { $$ = Stmt\Do_   [$4, toArray($2)]; }
191     | T_FOR '(' for_expr ';'  for_expr ';' for_expr ')' for_statement
192           { $$ = Stmt\For_[['init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => $9]]; }
193     | T_SWITCH parentheses_expr switch_case_list            { $$ = Stmt\Switch_[$2, $3]; }
194     | T_BREAK ';'                                           { $$ = Stmt\Break_[null]; }
195     | T_BREAK expr ';'                                      { $$ = Stmt\Break_[$2]; }
196     | T_CONTINUE ';'                                        { $$ = Stmt\Continue_[null]; }
197     | T_CONTINUE expr ';'                                   { $$ = Stmt\Continue_[$2]; }
198     | T_RETURN ';'                                          { $$ = Stmt\Return_[null]; }
199     | T_RETURN expr ';'                                     { $$ = Stmt\Return_[$2]; }
200     | T_GLOBAL global_var_list ';'                          { $$ = Stmt\Global_[$2]; }
201     | T_STATIC static_var_list ';'                          { $$ = Stmt\Static_[$2]; }
202     | T_ECHO expr_list ';'                                  { $$ = Stmt\Echo_[$2]; }
203     | T_INLINE_HTML                                         { $$ = Stmt\InlineHTML[$1]; }
204     | yield_expr ';'                                        { $$ = Stmt\Expression[$1]; }
205     | expr ';'                                              { $$ = Stmt\Expression[$1]; }
206     | T_UNSET '(' variables_list ')' ';'                    { $$ = Stmt\Unset_[$3]; }
207     | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
208           { $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; }
209     | T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement
210           { $$ = Stmt\Foreach_[$3, $7[0], ['keyVar' => $5, 'byRef' => $7[1], 'stmts' => $9]]; }
211     | T_DECLARE '(' declare_list ')' declare_statement      { $$ = Stmt\Declare_[$3, $5]; }
212     | T_TRY '{' inner_statement_list '}' catches optional_finally
213           { $$ = Stmt\TryCatch[$3, $5, $6]; $this->checkTryCatch($$); }
214     | T_THROW expr ';'                                      { $$ = Stmt\Throw_[$2]; }
215     | T_GOTO identifier ';'                                 { $$ = Stmt\Goto_[$2]; }
216     | identifier ':'                                        { $$ = Stmt\Label[$1]; }
217     | expr error                                            { $$ = Stmt\Expression[$1]; }
218     | error                                                 { $$ = array(); /* means: no statement */ }
219 ;
220
221 statement:
222       non_empty_statement                                   { $$ = $1; }
223     | ';'
224           { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
225             if ($$ === null) $$ = array(); /* means: no statement */ }
226 ;
227
228 catches:
229       /* empty */                                           { init(); }
230     | catches catch                                         { push($1, $2); }
231 ;
232
233 catch:
234     T_CATCH '(' name plain_variable ')' '{' inner_statement_list '}'
235         { $$ = Stmt\Catch_[array($3), $4, $7]; }
236 ;
237
238 optional_finally:
239       /* empty */                                           { $$ = null; }
240     | T_FINALLY '{' inner_statement_list '}'                { $$ = Stmt\Finally_[$3]; }
241 ;
242
243 variables_list:
244       variable                                              { init($1); }
245     | variables_list ',' variable                           { push($1, $3); }
246 ;
247
248 optional_ref:
249       /* empty */                                           { $$ = false; }
250     | '&'                                                   { $$ = true; }
251 ;
252
253 optional_ellipsis:
254       /* empty */                                           { $$ = false; }
255     | T_ELLIPSIS                                            { $$ = true; }
256 ;
257
258 function_declaration_statement:
259     T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
260         { $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
261 ;
262
263 class_declaration_statement:
264       class_entry_type identifier extends_from implements_list '{' class_statement_list '}'
265           { $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6]];
266             $this->checkClass($$, #2); }
267     | T_INTERFACE identifier interface_extends_list '{' class_statement_list '}'
268           { $$ = Stmt\Interface_[$2, ['extends' => $3, 'stmts' => $5]];
269             $this->checkInterface($$, #2); }
270     | T_TRAIT identifier '{' class_statement_list '}'
271           { $$ = Stmt\Trait_[$2, ['stmts' => $4]]; }
272 ;
273
274 class_entry_type:
275       T_CLASS                                               { $$ = 0; }
276     | T_ABSTRACT T_CLASS                                    { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
277     | T_FINAL T_CLASS                                       { $$ = Stmt\Class_::MODIFIER_FINAL; }
278 ;
279
280 extends_from:
281       /* empty */                                           { $$ = null; }
282     | T_EXTENDS class_name                                  { $$ = $2; }
283 ;
284
285 interface_extends_list:
286       /* empty */                                           { $$ = array(); }
287     | T_EXTENDS class_name_list                             { $$ = $2; }
288 ;
289
290 implements_list:
291       /* empty */                                           { $$ = array(); }
292     | T_IMPLEMENTS class_name_list                          { $$ = $2; }
293 ;
294
295 class_name_list:
296       class_name                                            { init($1); }
297     | class_name_list ',' class_name                        { push($1, $3); }
298 ;
299
300 for_statement:
301       statement                                             { $$ = toArray($1); }
302     | ':' inner_statement_list T_ENDFOR ';'                 { $$ = $2; }
303 ;
304
305 foreach_statement:
306       statement                                             { $$ = toArray($1); }
307     | ':' inner_statement_list T_ENDFOREACH ';'             { $$ = $2; }
308 ;
309
310 declare_statement:
311       non_empty_statement                                   { $$ = toArray($1); }
312     | ';'                                                   { $$ = null; }
313     | ':' inner_statement_list T_ENDDECLARE ';'             { $$ = $2; }
314 ;
315
316 declare_list:
317       declare_list_element                                  { init($1); }
318     | declare_list ',' declare_list_element                 { push($1, $3); }
319 ;
320
321 declare_list_element:
322       identifier '=' static_scalar                          { $$ = Stmt\DeclareDeclare[$1, $3]; }
323 ;
324
325 switch_case_list:
326       '{' case_list '}'                                     { $$ = $2; }
327     | '{' ';' case_list '}'                                 { $$ = $3; }
328     | ':' case_list T_ENDSWITCH ';'                         { $$ = $2; }
329     | ':' ';' case_list T_ENDSWITCH ';'                     { $$ = $3; }
330 ;
331
332 case_list:
333       /* empty */                                           { init(); }
334     | case_list case                                        { push($1, $2); }
335 ;
336
337 case:
338       T_CASE expr case_separator inner_statement_list_ex    { $$ = Stmt\Case_[$2, $4]; }
339     | T_DEFAULT case_separator inner_statement_list_ex      { $$ = Stmt\Case_[null, $3]; }
340 ;
341
342 case_separator:
343       ':'
344     | ';'
345 ;
346
347 while_statement:
348       statement                                             { $$ = toArray($1); }
349     | ':' inner_statement_list T_ENDWHILE ';'               { $$ = $2; }
350 ;
351
352 elseif_list:
353       /* empty */                                           { init(); }
354     | elseif_list elseif                                    { push($1, $2); }
355 ;
356
357 elseif:
358       T_ELSEIF parentheses_expr statement                   { $$ = Stmt\ElseIf_[$2, toArray($3)]; }
359 ;
360
361 new_elseif_list:
362       /* empty */                                           { init(); }
363     | new_elseif_list new_elseif                            { push($1, $2); }
364 ;
365
366 new_elseif:
367      T_ELSEIF parentheses_expr ':' inner_statement_list     { $$ = Stmt\ElseIf_[$2, $4]; }
368 ;
369
370 else_single:
371       /* empty */                                           { $$ = null; }
372     | T_ELSE statement                                      { $$ = Stmt\Else_[toArray($2)]; }
373 ;
374
375 new_else_single:
376       /* empty */                                           { $$ = null; }
377     | T_ELSE ':' inner_statement_list                       { $$ = Stmt\Else_[$3]; }
378 ;
379
380 foreach_variable:
381       variable                                              { $$ = array($1, false); }
382     | '&' variable                                          { $$ = array($2, true); }
383     | list_expr                                             { $$ = array($1, false); }
384 ;
385
386 parameter_list:
387       non_empty_parameter_list                              { $$ = $1; }
388     | /* empty */                                           { $$ = array(); }
389 ;
390
391 non_empty_parameter_list:
392       parameter                                             { init($1); }
393     | non_empty_parameter_list ',' parameter                { push($1, $3); }
394 ;
395
396 parameter:
397       optional_param_type optional_ref optional_ellipsis plain_variable
398           { $$ = Node\Param[$4, null, $1, $2, $3]; $this->checkParam($$); }
399     | optional_param_type optional_ref optional_ellipsis plain_variable '=' static_scalar
400           { $$ = Node\Param[$4, $6, $1, $2, $3]; $this->checkParam($$); }
401 ;
402
403 type:
404       name                                                  { $$ = $1; }
405     | T_ARRAY                                               { $$ = Node\Identifier['array']; }
406     | T_CALLABLE                                            { $$ = Node\Identifier['callable']; }
407 ;
408
409 optional_param_type:
410       /* empty */                                           { $$ = null; }
411     | type                                                  { $$ = $1; }
412 ;
413
414 optional_return_type:
415       /* empty */                                           { $$ = null; }
416     | ':' type                                              { $$ = $2; }
417 ;
418
419 argument_list:
420       '(' ')'                                               { $$ = array(); }
421     | '(' non_empty_argument_list ')'                       { $$ = $2; }
422     | '(' yield_expr ')'                                    { $$ = array(Node\Arg[$2, false, false]); }
423 ;
424
425 non_empty_argument_list:
426       argument                                              { init($1); }
427     | non_empty_argument_list ',' argument                  { push($1, $3); }
428 ;
429
430 argument:
431       expr                                                  { $$ = Node\Arg[$1, false, false]; }
432     | '&' variable                                          { $$ = Node\Arg[$2, true, false]; }
433     | T_ELLIPSIS expr                                       { $$ = Node\Arg[$2, false, true]; }
434 ;
435
436 global_var_list:
437       global_var_list ',' global_var                        { push($1, $3); }
438     | global_var                                            { init($1); }
439 ;
440
441 global_var:
442       plain_variable                                        { $$ = $1; }
443     | '$' variable                                          { $$ = Expr\Variable[$2]; }
444     | '$' '{' expr '}'                                      { $$ = Expr\Variable[$3]; }
445 ;
446
447 static_var_list:
448       static_var_list ',' static_var                        { push($1, $3); }
449     | static_var                                            { init($1); }
450 ;
451
452 static_var:
453       plain_variable                                        { $$ = Stmt\StaticVar[$1, null]; }
454     | plain_variable '=' static_scalar                      { $$ = Stmt\StaticVar[$1, $3]; }
455 ;
456
457 class_statement_list:
458       class_statement_list class_statement                  { push($1, $2); }
459     | /* empty */                                           { init(); }
460 ;
461
462 class_statement:
463       variable_modifiers property_declaration_list ';'
464           { $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); }
465     | T_CONST class_const_list ';'                          { $$ = Stmt\ClassConst[$2, 0]; }
466     | method_modifiers T_FUNCTION optional_ref identifier_ex '(' parameter_list ')' optional_return_type method_body
467           { $$ = Stmt\ClassMethod[$4, ['type' => $1, 'byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9]];
468             $this->checkClassMethod($$, #1); }
469     | T_USE class_name_list trait_adaptations               { $$ = Stmt\TraitUse[$2, $3]; }
470 ;
471
472 trait_adaptations:
473       ';'                                                   { $$ = array(); }
474     | '{' trait_adaptation_list '}'                         { $$ = $2; }
475 ;
476
477 trait_adaptation_list:
478       /* empty */                                           { init(); }
479     | trait_adaptation_list trait_adaptation                { push($1, $2); }
480 ;
481
482 trait_adaptation:
483       trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';'
484           { $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; }
485     | trait_method_reference T_AS member_modifier identifier_ex ';'
486           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; }
487     | trait_method_reference T_AS member_modifier ';'
488           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; }
489     | trait_method_reference T_AS identifier ';'
490           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
491     | trait_method_reference T_AS reserved_non_modifiers_identifier ';'
492           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
493 ;
494
495 trait_method_reference_fully_qualified:
496       name T_PAAMAYIM_NEKUDOTAYIM identifier_ex             { $$ = array($1, $3); }
497 ;
498 trait_method_reference:
499       trait_method_reference_fully_qualified                { $$ = $1; }
500     | identifier_ex                                         { $$ = array(null, $1); }
501 ;
502
503 method_body:
504       ';' /* abstract method */                             { $$ = null; }
505     | '{' inner_statement_list '}'                          { $$ = $2; }
506 ;
507
508 variable_modifiers:
509       non_empty_member_modifiers                            { $$ = $1; }
510     | T_VAR                                                 { $$ = 0; }
511 ;
512
513 method_modifiers:
514       /* empty */                                           { $$ = 0; }
515     | non_empty_member_modifiers                            { $$ = $1; }
516 ;
517
518 non_empty_member_modifiers:
519       member_modifier                                       { $$ = $1; }
520     | non_empty_member_modifiers member_modifier            { $this->checkModifier($1, $2, #2); $$ = $1 | $2; }
521 ;
522
523 member_modifier:
524       T_PUBLIC                                              { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
525     | T_PROTECTED                                           { $$ = Stmt\Class_::MODIFIER_PROTECTED; }
526     | T_PRIVATE                                             { $$ = Stmt\Class_::MODIFIER_PRIVATE; }
527     | T_STATIC                                              { $$ = Stmt\Class_::MODIFIER_STATIC; }
528     | T_ABSTRACT                                            { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
529     | T_FINAL                                               { $$ = Stmt\Class_::MODIFIER_FINAL; }
530 ;
531
532 property_declaration_list:
533       property_declaration                                  { init($1); }
534     | property_declaration_list ',' property_declaration    { push($1, $3); }
535 ;
536
537 property_decl_name:
538       T_VARIABLE                                            { $$ = Node\VarLikeIdentifier[parseVar($1)]; }
539 ;
540
541 property_declaration:
542       property_decl_name                                    { $$ = Stmt\PropertyProperty[$1, null]; }
543     | property_decl_name '=' static_scalar                  { $$ = Stmt\PropertyProperty[$1, $3]; }
544 ;
545
546 expr_list:
547       expr_list ',' expr                                    { push($1, $3); }
548     | expr                                                  { init($1); }
549 ;
550
551 for_expr:
552       /* empty */                                           { $$ = array(); }
553     | expr_list                                             { $$ = $1; }
554 ;
555
556 expr:
557       variable                                              { $$ = $1; }
558     | list_expr '=' expr                                    { $$ = Expr\Assign[$1, $3]; }
559     | variable '=' expr                                     { $$ = Expr\Assign[$1, $3]; }
560     | variable '=' '&' variable                             { $$ = Expr\AssignRef[$1, $4]; }
561     | variable '=' '&' new_expr                             { $$ = Expr\AssignRef[$1, $4]; }
562     | new_expr                                              { $$ = $1; }
563     | T_CLONE expr                                          { $$ = Expr\Clone_[$2]; }
564     | variable T_PLUS_EQUAL expr                            { $$ = Expr\AssignOp\Plus      [$1, $3]; }
565     | variable T_MINUS_EQUAL expr                           { $$ = Expr\AssignOp\Minus     [$1, $3]; }
566     | variable T_MUL_EQUAL expr                             { $$ = Expr\AssignOp\Mul       [$1, $3]; }
567     | variable T_DIV_EQUAL expr                             { $$ = Expr\AssignOp\Div       [$1, $3]; }
568     | variable T_CONCAT_EQUAL expr                          { $$ = Expr\AssignOp\Concat    [$1, $3]; }
569     | variable T_MOD_EQUAL expr                             { $$ = Expr\AssignOp\Mod       [$1, $3]; }
570     | variable T_AND_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseAnd[$1, $3]; }
571     | variable T_OR_EQUAL expr                              { $$ = Expr\AssignOp\BitwiseOr [$1, $3]; }
572     | variable T_XOR_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseXor[$1, $3]; }
573     | variable T_SL_EQUAL expr                              { $$ = Expr\AssignOp\ShiftLeft [$1, $3]; }
574     | variable T_SR_EQUAL expr                              { $$ = Expr\AssignOp\ShiftRight[$1, $3]; }
575     | variable T_POW_EQUAL expr                             { $$ = Expr\AssignOp\Pow       [$1, $3]; }
576     | variable T_INC                                        { $$ = Expr\PostInc[$1]; }
577     | T_INC variable                                        { $$ = Expr\PreInc [$2]; }
578     | variable T_DEC                                        { $$ = Expr\PostDec[$1]; }
579     | T_DEC variable                                        { $$ = Expr\PreDec [$2]; }
580     | expr T_BOOLEAN_OR expr                                { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; }
581     | expr T_BOOLEAN_AND expr                               { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; }
582     | expr T_LOGICAL_OR expr                                { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; }
583     | expr T_LOGICAL_AND expr                               { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; }
584     | expr T_LOGICAL_XOR expr                               { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; }
585     | expr '|' expr                                         { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; }
586     | expr '&' expr                                         { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
587     | expr '^' expr                                         { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; }
588     | expr '.' expr                                         { $$ = Expr\BinaryOp\Concat    [$1, $3]; }
589     | expr '+' expr                                         { $$ = Expr\BinaryOp\Plus      [$1, $3]; }
590     | expr '-' expr                                         { $$ = Expr\BinaryOp\Minus     [$1, $3]; }
591     | expr '*' expr                                         { $$ = Expr\BinaryOp\Mul       [$1, $3]; }
592     | expr '/' expr                                         { $$ = Expr\BinaryOp\Div       [$1, $3]; }
593     | expr '%' expr                                         { $$ = Expr\BinaryOp\Mod       [$1, $3]; }
594     | expr T_SL expr                                        { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; }
595     | expr T_SR expr                                        { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; }
596     | expr T_POW expr                                       { $$ = Expr\BinaryOp\Pow       [$1, $3]; }
597     | '+' expr %prec T_INC                                  { $$ = Expr\UnaryPlus [$2]; }
598     | '-' expr %prec T_INC                                  { $$ = Expr\UnaryMinus[$2]; }
599     | '!' expr                                              { $$ = Expr\BooleanNot[$2]; }
600     | '~' expr                                              { $$ = Expr\BitwiseNot[$2]; }
601     | expr T_IS_IDENTICAL expr                              { $$ = Expr\BinaryOp\Identical     [$1, $3]; }
602     | expr T_IS_NOT_IDENTICAL expr                          { $$ = Expr\BinaryOp\NotIdentical  [$1, $3]; }
603     | expr T_IS_EQUAL expr                                  { $$ = Expr\BinaryOp\Equal         [$1, $3]; }
604     | expr T_IS_NOT_EQUAL expr                              { $$ = Expr\BinaryOp\NotEqual      [$1, $3]; }
605     | expr T_SPACESHIP expr                                 { $$ = Expr\BinaryOp\Spaceship     [$1, $3]; }
606     | expr '<' expr                                         { $$ = Expr\BinaryOp\Smaller       [$1, $3]; }
607     | expr T_IS_SMALLER_OR_EQUAL expr                       { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; }
608     | expr '>' expr                                         { $$ = Expr\BinaryOp\Greater       [$1, $3]; }
609     | expr T_IS_GREATER_OR_EQUAL expr                       { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; }
610     | expr T_INSTANCEOF class_name_reference                { $$ = Expr\Instanceof_[$1, $3]; }
611     | parentheses_expr                                      { $$ = $1; }
612     /* we need a separate '(' new_expr ')' rule to avoid problems caused by a s/r conflict */
613     | '(' new_expr ')'                                      { $$ = $2; }
614     | expr '?' expr ':' expr                                { $$ = Expr\Ternary[$1, $3,   $5]; }
615     | expr '?' ':' expr                                     { $$ = Expr\Ternary[$1, null, $4]; }
616     | expr T_COALESCE expr                                  { $$ = Expr\BinaryOp\Coalesce[$1, $3]; }
617     | T_ISSET '(' variables_list ')'                        { $$ = Expr\Isset_[$3]; }
618     | T_EMPTY '(' expr ')'                                  { $$ = Expr\Empty_[$3]; }
619     | T_INCLUDE expr                                        { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; }
620     | T_INCLUDE_ONCE expr                                   { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; }
621     | T_EVAL parentheses_expr                               { $$ = Expr\Eval_[$2]; }
622     | T_REQUIRE expr                                        { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE]; }
623     | T_REQUIRE_ONCE expr                                   { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE_ONCE]; }
624     | T_INT_CAST expr                                       { $$ = Expr\Cast\Int_    [$2]; }
625     | T_DOUBLE_CAST expr                                    { $$ = Expr\Cast\Double  [$2]; }
626     | T_STRING_CAST expr                                    { $$ = Expr\Cast\String_ [$2]; }
627     | T_ARRAY_CAST expr                                     { $$ = Expr\Cast\Array_  [$2]; }
628     | T_OBJECT_CAST expr                                    { $$ = Expr\Cast\Object_ [$2]; }
629     | T_BOOL_CAST expr                                      { $$ = Expr\Cast\Bool_   [$2]; }
630     | T_UNSET_CAST expr                                     { $$ = Expr\Cast\Unset_  [$2]; }
631     | T_EXIT exit_expr
632           { $attrs = attributes();
633             $attrs['kind'] = strtolower($1) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE;
634             $$ = new Expr\Exit_($2, $attrs); }
635     | '@' expr                                              { $$ = Expr\ErrorSuppress[$2]; }
636     | scalar                                                { $$ = $1; }
637     | array_expr                                            { $$ = $1; }
638     | scalar_dereference                                    { $$ = $1; }
639     | '`' backticks_expr '`'                                { $$ = Expr\ShellExec[$2]; }
640     | T_PRINT expr                                          { $$ = Expr\Print_[$2]; }
641     | T_YIELD                                               { $$ = Expr\Yield_[null, null]; }
642     | T_YIELD_FROM expr                                     { $$ = Expr\YieldFrom[$2]; }
643     | T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
644       '{' inner_statement_list '}'
645           { $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $9]]; }
646     | T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
647       '{' inner_statement_list '}'
648           { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $10]]; }
649 ;
650
651 parentheses_expr:
652       '(' expr ')'                                          { $$ = $2; }
653     | '(' yield_expr ')'                                    { $$ = $2; }
654 ;
655
656 yield_expr:
657       T_YIELD expr                                          { $$ = Expr\Yield_[$2, null]; }
658     | T_YIELD expr T_DOUBLE_ARROW expr                      { $$ = Expr\Yield_[$4, $2]; }
659 ;
660
661 array_expr:
662       T_ARRAY '(' array_pair_list ')'
663           { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG;
664             $$ = new Expr\Array_($3, $attrs); }
665     | '[' array_pair_list ']'
666           { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT;
667             $$ = new Expr\Array_($2, $attrs); }
668 ;
669
670 scalar_dereference:
671       array_expr '[' dim_offset ']'                         { $$ = Expr\ArrayDimFetch[$1, $3]; }
672     | T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
673           { $attrs = attributes(); $attrs['kind'] = strKind($1);
674             $$ = Expr\ArrayDimFetch[new Scalar\String_(Scalar\String_::parse($1), $attrs), $3]; }
675     | constant '[' dim_offset ']'                           { $$ = Expr\ArrayDimFetch[$1, $3]; }
676     | scalar_dereference '[' dim_offset ']'                 { $$ = Expr\ArrayDimFetch[$1, $3]; }
677     /* alternative array syntax missing intentionally */
678 ;
679
680 anonymous_class:
681       T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
682           { $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $3, 'implements' => $4, 'stmts' => $6]], $2);
683             $this->checkClass($$[0], -1); }
684 ;
685
686 new_expr:
687       T_NEW class_name_reference ctor_arguments             { $$ = Expr\New_[$2, $3]; }
688     | T_NEW anonymous_class
689           { list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; }
690 ;
691
692 lexical_vars:
693       /* empty */                                           { $$ = array(); }
694     | T_USE '(' lexical_var_list ')'                        { $$ = $3; }
695 ;
696
697 lexical_var_list:
698       lexical_var                                           { init($1); }
699     | lexical_var_list ',' lexical_var                      { push($1, $3); }
700 ;
701
702 lexical_var:
703       optional_ref plain_variable                           { $$ = Expr\ClosureUse[$2, $1]; }
704 ;
705
706 function_call:
707       name argument_list                                    { $$ = Expr\FuncCall[$1, $2]; }
708     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex argument_list
709           { $$ = Expr\StaticCall[$1, $3, $4]; }
710     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' argument_list
711           { $$ = Expr\StaticCall[$1, $4, $6]; }
712     | static_property argument_list
713           { $$ = $this->fixupPhp5StaticPropCall($1, $2, attributes()); }
714     | variable_without_objects argument_list
715           { $$ = Expr\FuncCall[$1, $2]; }
716     | function_call '[' dim_offset ']'                      { $$ = Expr\ArrayDimFetch[$1, $3]; }
717       /* alternative array syntax missing intentionally */
718 ;
719
720 class_name:
721       T_STATIC                                              { $$ = Name[$1]; }
722     | name                                                  { $$ = $1; }
723 ;
724
725 name:
726       namespace_name_parts                                  { $$ = Name[$1]; }
727     | T_NS_SEPARATOR namespace_name_parts                   { $$ = Name\FullyQualified[$2]; }
728     | T_NAMESPACE T_NS_SEPARATOR namespace_name_parts       { $$ = Name\Relative[$3]; }
729 ;
730
731 class_name_reference:
732       class_name                                            { $$ = $1; }
733     | dynamic_class_name_reference                          { $$ = $1; }
734 ;
735
736 dynamic_class_name_reference:
737       object_access_for_dcnr                                { $$ = $1; }
738     | base_variable                                         { $$ = $1; }
739 ;
740
741 class_name_or_var:
742       class_name                                            { $$ = $1; }
743     | reference_variable                                    { $$ = $1; }
744 ;
745
746 object_access_for_dcnr:
747       base_variable T_OBJECT_OPERATOR object_property
748           { $$ = Expr\PropertyFetch[$1, $3]; }
749     | object_access_for_dcnr T_OBJECT_OPERATOR object_property
750           { $$ = Expr\PropertyFetch[$1, $3]; }
751     | object_access_for_dcnr '[' dim_offset ']'             { $$ = Expr\ArrayDimFetch[$1, $3]; }
752     | object_access_for_dcnr '{' expr '}'                   { $$ = Expr\ArrayDimFetch[$1, $3]; }
753 ;
754
755 exit_expr:
756       /* empty */                                           { $$ = null; }
757     | '(' ')'                                               { $$ = null; }
758     | parentheses_expr                                      { $$ = $1; }
759 ;
760
761 backticks_expr:
762       /* empty */                                           { $$ = array(); }
763     | T_ENCAPSED_AND_WHITESPACE
764           { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`', false)]); }
765     | encaps_list                                           { parseEncapsed($1, '`', false); $$ = $1; }
766 ;
767
768 ctor_arguments:
769       /* empty */                                           { $$ = array(); }
770     | argument_list                                         { $$ = $1; }
771 ;
772
773 common_scalar:
774       T_LNUMBER                                             { $$ = $this->parseLNumber($1, attributes(), true); }
775     | T_DNUMBER                                             { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; }
776     | T_CONSTANT_ENCAPSED_STRING
777           { $attrs = attributes(); $attrs['kind'] = strKind($1);
778             $$ = new Scalar\String_(Scalar\String_::parse($1, false), $attrs); }
779     | T_LINE                                                { $$ = Scalar\MagicConst\Line[]; }
780     | T_FILE                                                { $$ = Scalar\MagicConst\File[]; }
781     | T_DIR                                                 { $$ = Scalar\MagicConst\Dir[]; }
782     | T_CLASS_C                                             { $$ = Scalar\MagicConst\Class_[]; }
783     | T_TRAIT_C                                             { $$ = Scalar\MagicConst\Trait_[]; }
784     | T_METHOD_C                                            { $$ = Scalar\MagicConst\Method[]; }
785     | T_FUNC_C                                              { $$ = Scalar\MagicConst\Function_[]; }
786     | T_NS_C                                                { $$ = Scalar\MagicConst\Namespace_[]; }
787     | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
788           { $attrs = attributes(); setDocStringAttrs($attrs, $1);
789             $$ = new Scalar\String_(Scalar\String_::parseDocString($1, $2, false), $attrs); }
790     | T_START_HEREDOC T_END_HEREDOC
791           { $attrs = attributes(); setDocStringAttrs($attrs, $1);
792             $$ = new Scalar\String_('', $attrs); }
793 ;
794
795 static_scalar:
796       common_scalar                                         { $$ = $1; }
797     | class_name T_PAAMAYIM_NEKUDOTAYIM identifier_ex       { $$ = Expr\ClassConstFetch[$1, $3]; }
798     | name                                                  { $$ = Expr\ConstFetch[$1]; }
799     | T_ARRAY '(' static_array_pair_list ')'                { $$ = Expr\Array_[$3]; }
800     | '[' static_array_pair_list ']'                        { $$ = Expr\Array_[$2]; }
801     | static_operation                                      { $$ = $1; }
802 ;
803
804 static_operation:
805       static_scalar T_BOOLEAN_OR static_scalar              { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; }
806     | static_scalar T_BOOLEAN_AND static_scalar             { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; }
807     | static_scalar T_LOGICAL_OR static_scalar              { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; }
808     | static_scalar T_LOGICAL_AND static_scalar             { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; }
809     | static_scalar T_LOGICAL_XOR static_scalar             { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; }
810     | static_scalar '|' static_scalar                       { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; }
811     | static_scalar '&' static_scalar                       { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
812     | static_scalar '^' static_scalar                       { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; }
813     | static_scalar '.' static_scalar                       { $$ = Expr\BinaryOp\Concat    [$1, $3]; }
814     | static_scalar '+' static_scalar                       { $$ = Expr\BinaryOp\Plus      [$1, $3]; }
815     | static_scalar '-' static_scalar                       { $$ = Expr\BinaryOp\Minus     [$1, $3]; }
816     | static_scalar '*' static_scalar                       { $$ = Expr\BinaryOp\Mul       [$1, $3]; }
817     | static_scalar '/' static_scalar                       { $$ = Expr\BinaryOp\Div       [$1, $3]; }
818     | static_scalar '%' static_scalar                       { $$ = Expr\BinaryOp\Mod       [$1, $3]; }
819     | static_scalar T_SL static_scalar                      { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; }
820     | static_scalar T_SR static_scalar                      { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; }
821     | static_scalar T_POW static_scalar                     { $$ = Expr\BinaryOp\Pow       [$1, $3]; }
822     | '+' static_scalar %prec T_INC                         { $$ = Expr\UnaryPlus [$2]; }
823     | '-' static_scalar %prec T_INC                         { $$ = Expr\UnaryMinus[$2]; }
824     | '!' static_scalar                                     { $$ = Expr\BooleanNot[$2]; }
825     | '~' static_scalar                                     { $$ = Expr\BitwiseNot[$2]; }
826     | static_scalar T_IS_IDENTICAL static_scalar            { $$ = Expr\BinaryOp\Identical     [$1, $3]; }
827     | static_scalar T_IS_NOT_IDENTICAL static_scalar        { $$ = Expr\BinaryOp\NotIdentical  [$1, $3]; }
828     | static_scalar T_IS_EQUAL static_scalar                { $$ = Expr\BinaryOp\Equal         [$1, $3]; }
829     | static_scalar T_IS_NOT_EQUAL static_scalar            { $$ = Expr\BinaryOp\NotEqual      [$1, $3]; }
830     | static_scalar '<' static_scalar                       { $$ = Expr\BinaryOp\Smaller       [$1, $3]; }
831     | static_scalar T_IS_SMALLER_OR_EQUAL static_scalar     { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; }
832     | static_scalar '>' static_scalar                       { $$ = Expr\BinaryOp\Greater       [$1, $3]; }
833     | static_scalar T_IS_GREATER_OR_EQUAL static_scalar     { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; }
834     | static_scalar '?' static_scalar ':' static_scalar     { $$ = Expr\Ternary[$1, $3,   $5]; }
835     | static_scalar '?' ':' static_scalar                   { $$ = Expr\Ternary[$1, null, $4]; }
836     | static_scalar '[' static_scalar ']'                   { $$ = Expr\ArrayDimFetch[$1, $3]; }
837     | '(' static_scalar ')'                                 { $$ = $2; }
838 ;
839
840 constant:
841       name                                                  { $$ = Expr\ConstFetch[$1]; }
842     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex
843           { $$ = Expr\ClassConstFetch[$1, $3]; }
844 ;
845
846 scalar:
847       common_scalar                                         { $$ = $1; }
848     | constant                                              { $$ = $1; }
849     | '"' encaps_list '"'
850           { $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED;
851             parseEncapsed($2, '"', true); $$ = new Scalar\Encapsed($2, $attrs); }
852     | T_START_HEREDOC encaps_list T_END_HEREDOC
853           { $attrs = attributes(); setDocStringAttrs($attrs, $1);
854             parseEncapsedDoc($2, true); $$ = new Scalar\Encapsed($2, $attrs); }
855 ;
856
857 static_array_pair_list:
858       /* empty */                                           { $$ = array(); }
859     | non_empty_static_array_pair_list optional_comma       { $$ = $1; }
860 ;
861
862 optional_comma:
863       /* empty */
864     | ','
865 ;
866
867 non_empty_static_array_pair_list:
868       non_empty_static_array_pair_list ',' static_array_pair { push($1, $3); }
869     | static_array_pair                                      { init($1); }
870 ;
871
872 static_array_pair:
873       static_scalar T_DOUBLE_ARROW static_scalar            { $$ = Expr\ArrayItem[$3, $1,   false]; }
874     | static_scalar                                         { $$ = Expr\ArrayItem[$1, null, false]; }
875 ;
876
877 variable:
878       object_access                                         { $$ = $1; }
879     | base_variable                                         { $$ = $1; }
880     | function_call                                         { $$ = $1; }
881     | new_expr_array_deref                                  { $$ = $1; }
882 ;
883
884 new_expr_array_deref:
885       '(' new_expr ')' '[' dim_offset ']'                   { $$ = Expr\ArrayDimFetch[$2, $5]; }
886     | new_expr_array_deref '[' dim_offset ']'               { $$ = Expr\ArrayDimFetch[$1, $3]; }
887       /* alternative array syntax missing intentionally */
888 ;
889
890 object_access:
891       variable_or_new_expr T_OBJECT_OPERATOR object_property
892           { $$ = Expr\PropertyFetch[$1, $3]; }
893     | variable_or_new_expr T_OBJECT_OPERATOR object_property argument_list
894           { $$ = Expr\MethodCall[$1, $3, $4]; }
895     | object_access argument_list                           { $$ = Expr\FuncCall[$1, $2]; }
896     | object_access '[' dim_offset ']'                      { $$ = Expr\ArrayDimFetch[$1, $3]; }
897     | object_access '{' expr '}'                            { $$ = Expr\ArrayDimFetch[$1, $3]; }
898 ;
899
900 variable_or_new_expr:
901       variable                                              { $$ = $1; }
902     | '(' new_expr ')'                                      { $$ = $2; }
903 ;
904
905 variable_without_objects:
906       reference_variable                                    { $$ = $1; }
907     | '$' variable_without_objects                          { $$ = Expr\Variable[$2]; }
908 ;
909
910 base_variable:
911       variable_without_objects                              { $$ = $1; }
912     | static_property                                       { $$ = $1; }
913 ;
914
915 static_property:
916       class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable
917           { $$ = Expr\StaticPropertyFetch[$1, $4]; }
918     | static_property_with_arrays                           { $$ = $1; }
919 ;
920
921 static_property_simple_name:
922       T_VARIABLE
923           { $var = parseVar($1); $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; }
924 ;
925
926 static_property_with_arrays:
927       class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_property_simple_name
928           { $$ = Expr\StaticPropertyFetch[$1, $3]; }
929     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
930           { $$ = Expr\StaticPropertyFetch[$1, $5]; }
931     | static_property_with_arrays '[' dim_offset ']'        { $$ = Expr\ArrayDimFetch[$1, $3]; }
932     | static_property_with_arrays '{' expr '}'              { $$ = Expr\ArrayDimFetch[$1, $3]; }
933 ;
934
935 reference_variable:
936       reference_variable '[' dim_offset ']'                 { $$ = Expr\ArrayDimFetch[$1, $3]; }
937     | reference_variable '{' expr '}'                       { $$ = Expr\ArrayDimFetch[$1, $3]; }
938     | plain_variable                                        { $$ = $1; }
939     | '$' '{' expr '}'                                      { $$ = Expr\Variable[$3]; }
940 ;
941
942 dim_offset:
943       /* empty */                                           { $$ = null; }
944     | expr                                                  { $$ = $1; }
945 ;
946
947 object_property:
948       identifier                                            { $$ = $1; }
949     | '{' expr '}'                                          { $$ = $2; }
950     | variable_without_objects                              { $$ = $1; }
951     | error                                                 { $$ = Expr\Error[]; $this->errorState = 2; }
952 ;
953
954 list_expr:
955       T_LIST '(' list_expr_elements ')'                     { $$ = Expr\List_[$3]; }
956 ;
957
958 list_expr_elements:
959       list_expr_elements ',' list_expr_element              { push($1, $3); }
960     | list_expr_element                                     { init($1); }
961 ;
962
963 list_expr_element:
964       variable                                              { $$ = Expr\ArrayItem[$1, null, false]; }
965     | list_expr                                             { $$ = Expr\ArrayItem[$1, null, false]; }
966     | /* empty */                                           { $$ = null; }
967 ;
968
969 array_pair_list:
970       /* empty */                                           { $$ = array(); }
971     | non_empty_array_pair_list optional_comma              { $$ = $1; }
972 ;
973
974 non_empty_array_pair_list:
975       non_empty_array_pair_list ',' array_pair              { push($1, $3); }
976     | array_pair                                            { init($1); }
977 ;
978
979 array_pair:
980       expr T_DOUBLE_ARROW expr                              { $$ = Expr\ArrayItem[$3, $1,   false]; }
981     | expr                                                  { $$ = Expr\ArrayItem[$1, null, false]; }
982     | expr T_DOUBLE_ARROW '&' variable                      { $$ = Expr\ArrayItem[$4, $1,   true]; }
983     | '&' variable                                          { $$ = Expr\ArrayItem[$2, null, true]; }
984 ;
985
986 encaps_list:
987       encaps_list encaps_var                                { push($1, $2); }
988     | encaps_list encaps_string_part                        { push($1, $2); }
989     | encaps_var                                            { init($1); }
990     | encaps_string_part encaps_var                         { init($1, $2); }
991 ;
992
993 encaps_string_part:
994       T_ENCAPSED_AND_WHITESPACE                             { $$ = Scalar\EncapsedStringPart[$1]; }
995 ;
996
997 encaps_str_varname:
998       T_STRING_VARNAME                                      { $$ = Expr\Variable[$1]; }
999 ;
1000
1001 encaps_var:
1002       plain_variable                                        { $$ = $1; }
1003     | plain_variable '[' encaps_var_offset ']'              { $$ = Expr\ArrayDimFetch[$1, $3]; }
1004     | plain_variable T_OBJECT_OPERATOR identifier           { $$ = Expr\PropertyFetch[$1, $3]; }
1005     | T_DOLLAR_OPEN_CURLY_BRACES expr '}'                   { $$ = Expr\Variable[$2]; }
1006     | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'       { $$ = Expr\Variable[$2]; }
1007     | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}'
1008           { $$ = Expr\ArrayDimFetch[$2, $4]; }
1009     | T_CURLY_OPEN variable '}'                             { $$ = $2; }
1010 ;
1011
1012 encaps_var_offset:
1013       T_STRING                                              { $$ = Scalar\String_[$1]; }
1014     | T_NUM_STRING                                          { $$ = $this->parseNumString($1, attributes()); }
1015     | plain_variable                                        { $$ = $1; }
1016 ;
1017
1018 %%