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