abc5cedfa134656d864ea6ef8dbf71abe702ff02
[yaffs-website] / 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_ex:
458       class_statement_list_ex class_statement               { if ($2 !== null) { push($1, $2); } }
459     | /* empty */                                           { init(); }
460 ;
461
462 class_statement_list:
463       class_statement_list_ex
464           { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
465             if ($nop !== null) { $1[] = $nop; } $$ = $1; }
466 ;
467
468 class_statement:
469       variable_modifiers property_declaration_list ';'
470           { $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); }
471     | T_CONST class_const_list ';'                          { $$ = Stmt\ClassConst[$2, 0]; }
472     | method_modifiers T_FUNCTION optional_ref identifier_ex '(' parameter_list ')' optional_return_type method_body
473           { $$ = Stmt\ClassMethod[$4, ['type' => $1, 'byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9]];
474             $this->checkClassMethod($$, #1); }
475     | T_USE class_name_list trait_adaptations               { $$ = Stmt\TraitUse[$2, $3]; }
476 ;
477
478 trait_adaptations:
479       ';'                                                   { $$ = array(); }
480     | '{' trait_adaptation_list '}'                         { $$ = $2; }
481 ;
482
483 trait_adaptation_list:
484       /* empty */                                           { init(); }
485     | trait_adaptation_list trait_adaptation                { push($1, $2); }
486 ;
487
488 trait_adaptation:
489       trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';'
490           { $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; }
491     | trait_method_reference T_AS member_modifier identifier_ex ';'
492           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; }
493     | trait_method_reference T_AS member_modifier ';'
494           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; }
495     | trait_method_reference T_AS identifier ';'
496           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
497     | trait_method_reference T_AS reserved_non_modifiers_identifier ';'
498           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
499 ;
500
501 trait_method_reference_fully_qualified:
502       name T_PAAMAYIM_NEKUDOTAYIM identifier_ex             { $$ = array($1, $3); }
503 ;
504 trait_method_reference:
505       trait_method_reference_fully_qualified                { $$ = $1; }
506     | identifier_ex                                         { $$ = array(null, $1); }
507 ;
508
509 method_body:
510       ';' /* abstract method */                             { $$ = null; }
511     | '{' inner_statement_list '}'                          { $$ = $2; }
512 ;
513
514 variable_modifiers:
515       non_empty_member_modifiers                            { $$ = $1; }
516     | T_VAR                                                 { $$ = 0; }
517 ;
518
519 method_modifiers:
520       /* empty */                                           { $$ = 0; }
521     | non_empty_member_modifiers                            { $$ = $1; }
522 ;
523
524 non_empty_member_modifiers:
525       member_modifier                                       { $$ = $1; }
526     | non_empty_member_modifiers member_modifier            { $this->checkModifier($1, $2, #2); $$ = $1 | $2; }
527 ;
528
529 member_modifier:
530       T_PUBLIC                                              { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
531     | T_PROTECTED                                           { $$ = Stmt\Class_::MODIFIER_PROTECTED; }
532     | T_PRIVATE                                             { $$ = Stmt\Class_::MODIFIER_PRIVATE; }
533     | T_STATIC                                              { $$ = Stmt\Class_::MODIFIER_STATIC; }
534     | T_ABSTRACT                                            { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
535     | T_FINAL                                               { $$ = Stmt\Class_::MODIFIER_FINAL; }
536 ;
537
538 property_declaration_list:
539       property_declaration                                  { init($1); }
540     | property_declaration_list ',' property_declaration    { push($1, $3); }
541 ;
542
543 property_decl_name:
544       T_VARIABLE                                            { $$ = Node\VarLikeIdentifier[parseVar($1)]; }
545 ;
546
547 property_declaration:
548       property_decl_name                                    { $$ = Stmt\PropertyProperty[$1, null]; }
549     | property_decl_name '=' static_scalar                  { $$ = Stmt\PropertyProperty[$1, $3]; }
550 ;
551
552 expr_list:
553       expr_list ',' expr                                    { push($1, $3); }
554     | expr                                                  { init($1); }
555 ;
556
557 for_expr:
558       /* empty */                                           { $$ = array(); }
559     | expr_list                                             { $$ = $1; }
560 ;
561
562 expr:
563       variable                                              { $$ = $1; }
564     | list_expr '=' expr                                    { $$ = Expr\Assign[$1, $3]; }
565     | variable '=' expr                                     { $$ = Expr\Assign[$1, $3]; }
566     | variable '=' '&' variable                             { $$ = Expr\AssignRef[$1, $4]; }
567     | variable '=' '&' new_expr                             { $$ = Expr\AssignRef[$1, $4]; }
568     | new_expr                                              { $$ = $1; }
569     | T_CLONE expr                                          { $$ = Expr\Clone_[$2]; }
570     | variable T_PLUS_EQUAL expr                            { $$ = Expr\AssignOp\Plus      [$1, $3]; }
571     | variable T_MINUS_EQUAL expr                           { $$ = Expr\AssignOp\Minus     [$1, $3]; }
572     | variable T_MUL_EQUAL expr                             { $$ = Expr\AssignOp\Mul       [$1, $3]; }
573     | variable T_DIV_EQUAL expr                             { $$ = Expr\AssignOp\Div       [$1, $3]; }
574     | variable T_CONCAT_EQUAL expr                          { $$ = Expr\AssignOp\Concat    [$1, $3]; }
575     | variable T_MOD_EQUAL expr                             { $$ = Expr\AssignOp\Mod       [$1, $3]; }
576     | variable T_AND_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseAnd[$1, $3]; }
577     | variable T_OR_EQUAL expr                              { $$ = Expr\AssignOp\BitwiseOr [$1, $3]; }
578     | variable T_XOR_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseXor[$1, $3]; }
579     | variable T_SL_EQUAL expr                              { $$ = Expr\AssignOp\ShiftLeft [$1, $3]; }
580     | variable T_SR_EQUAL expr                              { $$ = Expr\AssignOp\ShiftRight[$1, $3]; }
581     | variable T_POW_EQUAL expr                             { $$ = Expr\AssignOp\Pow       [$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                                    { $$ = Expr\Cast\Double  [$2]; }
632     | T_STRING_CAST expr                                    { $$ = Expr\Cast\String_ [$2]; }
633     | T_ARRAY_CAST expr                                     { $$ = Expr\Cast\Array_  [$2]; }
634     | T_OBJECT_CAST expr                                    { $$ = Expr\Cast\Object_ [$2]; }
635     | T_BOOL_CAST expr                                      { $$ = Expr\Cast\Bool_   [$2]; }
636     | T_UNSET_CAST expr                                     { $$ = Expr\Cast\Unset_  [$2]; }
637     | T_EXIT exit_expr
638           { $attrs = attributes();
639             $attrs['kind'] = strtolower($1) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE;
640             $$ = new Expr\Exit_($2, $attrs); }
641     | '@' expr                                              { $$ = Expr\ErrorSuppress[$2]; }
642     | scalar                                                { $$ = $1; }
643     | array_expr                                            { $$ = $1; }
644     | scalar_dereference                                    { $$ = $1; }
645     | '`' backticks_expr '`'                                { $$ = Expr\ShellExec[$2]; }
646     | T_PRINT expr                                          { $$ = Expr\Print_[$2]; }
647     | T_YIELD                                               { $$ = Expr\Yield_[null, null]; }
648     | T_YIELD_FROM expr                                     { $$ = Expr\YieldFrom[$2]; }
649     | T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
650       '{' inner_statement_list '}'
651           { $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $9]]; }
652     | T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
653       '{' inner_statement_list '}'
654           { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $10]]; }
655 ;
656
657 parentheses_expr:
658       '(' expr ')'                                          { $$ = $2; }
659     | '(' yield_expr ')'                                    { $$ = $2; }
660 ;
661
662 yield_expr:
663       T_YIELD expr                                          { $$ = Expr\Yield_[$2, null]; }
664     | T_YIELD expr T_DOUBLE_ARROW expr                      { $$ = Expr\Yield_[$4, $2]; }
665 ;
666
667 array_expr:
668       T_ARRAY '(' array_pair_list ')'
669           { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG;
670             $$ = new Expr\Array_($3, $attrs); }
671     | '[' array_pair_list ']'
672           { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT;
673             $$ = new Expr\Array_($2, $attrs); }
674 ;
675
676 scalar_dereference:
677       array_expr '[' dim_offset ']'                         { $$ = Expr\ArrayDimFetch[$1, $3]; }
678     | T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
679           { $attrs = attributes(); $attrs['kind'] = strKind($1);
680             $$ = Expr\ArrayDimFetch[new Scalar\String_(Scalar\String_::parse($1), $attrs), $3]; }
681     | constant '[' dim_offset ']'                           { $$ = Expr\ArrayDimFetch[$1, $3]; }
682     | scalar_dereference '[' dim_offset ']'                 { $$ = Expr\ArrayDimFetch[$1, $3]; }
683     /* alternative array syntax missing intentionally */
684 ;
685
686 anonymous_class:
687       T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
688           { $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $3, 'implements' => $4, 'stmts' => $6]], $2);
689             $this->checkClass($$[0], -1); }
690 ;
691
692 new_expr:
693       T_NEW class_name_reference ctor_arguments             { $$ = Expr\New_[$2, $3]; }
694     | T_NEW anonymous_class
695           { list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; }
696 ;
697
698 lexical_vars:
699       /* empty */                                           { $$ = array(); }
700     | T_USE '(' lexical_var_list ')'                        { $$ = $3; }
701 ;
702
703 lexical_var_list:
704       lexical_var                                           { init($1); }
705     | lexical_var_list ',' lexical_var                      { push($1, $3); }
706 ;
707
708 lexical_var:
709       optional_ref plain_variable                           { $$ = Expr\ClosureUse[$2, $1]; }
710 ;
711
712 function_call:
713       name argument_list                                    { $$ = Expr\FuncCall[$1, $2]; }
714     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex argument_list
715           { $$ = Expr\StaticCall[$1, $3, $4]; }
716     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' argument_list
717           { $$ = Expr\StaticCall[$1, $4, $6]; }
718     | static_property argument_list
719           { $$ = $this->fixupPhp5StaticPropCall($1, $2, attributes()); }
720     | variable_without_objects argument_list
721           { $$ = Expr\FuncCall[$1, $2]; }
722     | function_call '[' dim_offset ']'                      { $$ = Expr\ArrayDimFetch[$1, $3]; }
723       /* alternative array syntax missing intentionally */
724 ;
725
726 class_name:
727       T_STATIC                                              { $$ = Name[$1]; }
728     | name                                                  { $$ = $1; }
729 ;
730
731 name:
732       namespace_name_parts                                  { $$ = Name[$1]; }
733     | T_NS_SEPARATOR namespace_name_parts                   { $$ = Name\FullyQualified[$2]; }
734     | T_NAMESPACE T_NS_SEPARATOR namespace_name_parts       { $$ = Name\Relative[$3]; }
735 ;
736
737 class_name_reference:
738       class_name                                            { $$ = $1; }
739     | dynamic_class_name_reference                          { $$ = $1; }
740 ;
741
742 dynamic_class_name_reference:
743       object_access_for_dcnr                                { $$ = $1; }
744     | base_variable                                         { $$ = $1; }
745 ;
746
747 class_name_or_var:
748       class_name                                            { $$ = $1; }
749     | reference_variable                                    { $$ = $1; }
750 ;
751
752 object_access_for_dcnr:
753       base_variable T_OBJECT_OPERATOR object_property
754           { $$ = Expr\PropertyFetch[$1, $3]; }
755     | object_access_for_dcnr T_OBJECT_OPERATOR object_property
756           { $$ = Expr\PropertyFetch[$1, $3]; }
757     | object_access_for_dcnr '[' dim_offset ']'             { $$ = Expr\ArrayDimFetch[$1, $3]; }
758     | object_access_for_dcnr '{' expr '}'                   { $$ = Expr\ArrayDimFetch[$1, $3]; }
759 ;
760
761 exit_expr:
762       /* empty */                                           { $$ = null; }
763     | '(' ')'                                               { $$ = null; }
764     | parentheses_expr                                      { $$ = $1; }
765 ;
766
767 backticks_expr:
768       /* empty */                                           { $$ = array(); }
769     | T_ENCAPSED_AND_WHITESPACE
770           { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`', false)]); }
771     | encaps_list                                           { parseEncapsed($1, '`', false); $$ = $1; }
772 ;
773
774 ctor_arguments:
775       /* empty */                                           { $$ = array(); }
776     | argument_list                                         { $$ = $1; }
777 ;
778
779 common_scalar:
780       T_LNUMBER                                             { $$ = $this->parseLNumber($1, attributes(), true); }
781     | T_DNUMBER                                             { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; }
782     | T_CONSTANT_ENCAPSED_STRING
783           { $attrs = attributes(); $attrs['kind'] = strKind($1);
784             $$ = new Scalar\String_(Scalar\String_::parse($1, false), $attrs); }
785     | T_LINE                                                { $$ = Scalar\MagicConst\Line[]; }
786     | T_FILE                                                { $$ = Scalar\MagicConst\File[]; }
787     | T_DIR                                                 { $$ = Scalar\MagicConst\Dir[]; }
788     | T_CLASS_C                                             { $$ = Scalar\MagicConst\Class_[]; }
789     | T_TRAIT_C                                             { $$ = Scalar\MagicConst\Trait_[]; }
790     | T_METHOD_C                                            { $$ = Scalar\MagicConst\Method[]; }
791     | T_FUNC_C                                              { $$ = Scalar\MagicConst\Function_[]; }
792     | T_NS_C                                                { $$ = Scalar\MagicConst\Namespace_[]; }
793     | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
794           { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), false); }
795     | T_START_HEREDOC T_END_HEREDOC
796           { $$ = $this->parseDocString($1, '', $2, attributes(), stackAttributes(#2), false); }
797 ;
798
799 static_scalar:
800       common_scalar                                         { $$ = $1; }
801     | class_name T_PAAMAYIM_NEKUDOTAYIM identifier_ex       { $$ = Expr\ClassConstFetch[$1, $3]; }
802     | name                                                  { $$ = Expr\ConstFetch[$1]; }
803     | T_ARRAY '(' static_array_pair_list ')'                { $$ = Expr\Array_[$3]; }
804     | '[' static_array_pair_list ']'                        { $$ = Expr\Array_[$2]; }
805     | static_operation                                      { $$ = $1; }
806 ;
807
808 static_operation:
809       static_scalar T_BOOLEAN_OR static_scalar              { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; }
810     | static_scalar T_BOOLEAN_AND static_scalar             { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; }
811     | static_scalar T_LOGICAL_OR static_scalar              { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; }
812     | static_scalar T_LOGICAL_AND static_scalar             { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; }
813     | static_scalar T_LOGICAL_XOR static_scalar             { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; }
814     | static_scalar '|' static_scalar                       { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; }
815     | static_scalar '&' static_scalar                       { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
816     | static_scalar '^' static_scalar                       { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; }
817     | static_scalar '.' static_scalar                       { $$ = Expr\BinaryOp\Concat    [$1, $3]; }
818     | static_scalar '+' static_scalar                       { $$ = Expr\BinaryOp\Plus      [$1, $3]; }
819     | static_scalar '-' static_scalar                       { $$ = Expr\BinaryOp\Minus     [$1, $3]; }
820     | static_scalar '*' static_scalar                       { $$ = Expr\BinaryOp\Mul       [$1, $3]; }
821     | static_scalar '/' static_scalar                       { $$ = Expr\BinaryOp\Div       [$1, $3]; }
822     | static_scalar '%' static_scalar                       { $$ = Expr\BinaryOp\Mod       [$1, $3]; }
823     | static_scalar T_SL static_scalar                      { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; }
824     | static_scalar T_SR static_scalar                      { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; }
825     | static_scalar T_POW static_scalar                     { $$ = Expr\BinaryOp\Pow       [$1, $3]; }
826     | '+' static_scalar %prec T_INC                         { $$ = Expr\UnaryPlus [$2]; }
827     | '-' static_scalar %prec T_INC                         { $$ = Expr\UnaryMinus[$2]; }
828     | '!' static_scalar                                     { $$ = Expr\BooleanNot[$2]; }
829     | '~' static_scalar                                     { $$ = Expr\BitwiseNot[$2]; }
830     | static_scalar T_IS_IDENTICAL static_scalar            { $$ = Expr\BinaryOp\Identical     [$1, $3]; }
831     | static_scalar T_IS_NOT_IDENTICAL static_scalar        { $$ = Expr\BinaryOp\NotIdentical  [$1, $3]; }
832     | static_scalar T_IS_EQUAL static_scalar                { $$ = Expr\BinaryOp\Equal         [$1, $3]; }
833     | static_scalar T_IS_NOT_EQUAL static_scalar            { $$ = Expr\BinaryOp\NotEqual      [$1, $3]; }
834     | static_scalar '<' static_scalar                       { $$ = Expr\BinaryOp\Smaller       [$1, $3]; }
835     | static_scalar T_IS_SMALLER_OR_EQUAL static_scalar     { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; }
836     | static_scalar '>' static_scalar                       { $$ = Expr\BinaryOp\Greater       [$1, $3]; }
837     | static_scalar T_IS_GREATER_OR_EQUAL static_scalar     { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; }
838     | static_scalar '?' static_scalar ':' static_scalar     { $$ = Expr\Ternary[$1, $3,   $5]; }
839     | static_scalar '?' ':' static_scalar                   { $$ = Expr\Ternary[$1, null, $4]; }
840     | static_scalar '[' static_scalar ']'                   { $$ = Expr\ArrayDimFetch[$1, $3]; }
841     | '(' static_scalar ')'                                 { $$ = $2; }
842 ;
843
844 constant:
845       name                                                  { $$ = Expr\ConstFetch[$1]; }
846     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex
847           { $$ = Expr\ClassConstFetch[$1, $3]; }
848 ;
849
850 scalar:
851       common_scalar                                         { $$ = $1; }
852     | constant                                              { $$ = $1; }
853     | '"' encaps_list '"'
854           { $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED;
855             parseEncapsed($2, '"', true); $$ = new Scalar\Encapsed($2, $attrs); }
856     | T_START_HEREDOC encaps_list T_END_HEREDOC
857           { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), true); }
858 ;
859
860 static_array_pair_list:
861       /* empty */                                           { $$ = array(); }
862     | non_empty_static_array_pair_list optional_comma       { $$ = $1; }
863 ;
864
865 optional_comma:
866       /* empty */
867     | ','
868 ;
869
870 non_empty_static_array_pair_list:
871       non_empty_static_array_pair_list ',' static_array_pair { push($1, $3); }
872     | static_array_pair                                      { init($1); }
873 ;
874
875 static_array_pair:
876       static_scalar T_DOUBLE_ARROW static_scalar            { $$ = Expr\ArrayItem[$3, $1,   false]; }
877     | static_scalar                                         { $$ = Expr\ArrayItem[$1, null, false]; }
878 ;
879
880 variable:
881       object_access                                         { $$ = $1; }
882     | base_variable                                         { $$ = $1; }
883     | function_call                                         { $$ = $1; }
884     | new_expr_array_deref                                  { $$ = $1; }
885 ;
886
887 new_expr_array_deref:
888       '(' new_expr ')' '[' dim_offset ']'                   { $$ = Expr\ArrayDimFetch[$2, $5]; }
889     | new_expr_array_deref '[' dim_offset ']'               { $$ = Expr\ArrayDimFetch[$1, $3]; }
890       /* alternative array syntax missing intentionally */
891 ;
892
893 object_access:
894       variable_or_new_expr T_OBJECT_OPERATOR object_property
895           { $$ = Expr\PropertyFetch[$1, $3]; }
896     | variable_or_new_expr T_OBJECT_OPERATOR object_property argument_list
897           { $$ = Expr\MethodCall[$1, $3, $4]; }
898     | object_access argument_list                           { $$ = Expr\FuncCall[$1, $2]; }
899     | object_access '[' dim_offset ']'                      { $$ = Expr\ArrayDimFetch[$1, $3]; }
900     | object_access '{' expr '}'                            { $$ = Expr\ArrayDimFetch[$1, $3]; }
901 ;
902
903 variable_or_new_expr:
904       variable                                              { $$ = $1; }
905     | '(' new_expr ')'                                      { $$ = $2; }
906 ;
907
908 variable_without_objects:
909       reference_variable                                    { $$ = $1; }
910     | '$' variable_without_objects                          { $$ = Expr\Variable[$2]; }
911 ;
912
913 base_variable:
914       variable_without_objects                              { $$ = $1; }
915     | static_property                                       { $$ = $1; }
916 ;
917
918 static_property:
919       class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable
920           { $$ = Expr\StaticPropertyFetch[$1, $4]; }
921     | static_property_with_arrays                           { $$ = $1; }
922 ;
923
924 static_property_simple_name:
925       T_VARIABLE
926           { $var = parseVar($1); $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; }
927 ;
928
929 static_property_with_arrays:
930       class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_property_simple_name
931           { $$ = Expr\StaticPropertyFetch[$1, $3]; }
932     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
933           { $$ = Expr\StaticPropertyFetch[$1, $5]; }
934     | static_property_with_arrays '[' dim_offset ']'        { $$ = Expr\ArrayDimFetch[$1, $3]; }
935     | static_property_with_arrays '{' expr '}'              { $$ = Expr\ArrayDimFetch[$1, $3]; }
936 ;
937
938 reference_variable:
939       reference_variable '[' dim_offset ']'                 { $$ = Expr\ArrayDimFetch[$1, $3]; }
940     | reference_variable '{' expr '}'                       { $$ = Expr\ArrayDimFetch[$1, $3]; }
941     | plain_variable                                        { $$ = $1; }
942     | '$' '{' expr '}'                                      { $$ = Expr\Variable[$3]; }
943 ;
944
945 dim_offset:
946       /* empty */                                           { $$ = null; }
947     | expr                                                  { $$ = $1; }
948 ;
949
950 object_property:
951       identifier                                            { $$ = $1; }
952     | '{' expr '}'                                          { $$ = $2; }
953     | variable_without_objects                              { $$ = $1; }
954     | error                                                 { $$ = Expr\Error[]; $this->errorState = 2; }
955 ;
956
957 list_expr:
958       T_LIST '(' list_expr_elements ')'                     { $$ = Expr\List_[$3]; }
959 ;
960
961 list_expr_elements:
962       list_expr_elements ',' list_expr_element              { push($1, $3); }
963     | list_expr_element                                     { init($1); }
964 ;
965
966 list_expr_element:
967       variable                                              { $$ = Expr\ArrayItem[$1, null, false]; }
968     | list_expr                                             { $$ = Expr\ArrayItem[$1, null, false]; }
969     | /* empty */                                           { $$ = null; }
970 ;
971
972 array_pair_list:
973       /* empty */                                           { $$ = array(); }
974     | non_empty_array_pair_list optional_comma              { $$ = $1; }
975 ;
976
977 non_empty_array_pair_list:
978       non_empty_array_pair_list ',' array_pair              { push($1, $3); }
979     | array_pair                                            { init($1); }
980 ;
981
982 array_pair:
983       expr T_DOUBLE_ARROW expr                              { $$ = Expr\ArrayItem[$3, $1,   false]; }
984     | expr                                                  { $$ = Expr\ArrayItem[$1, null, false]; }
985     | expr T_DOUBLE_ARROW '&' variable                      { $$ = Expr\ArrayItem[$4, $1,   true]; }
986     | '&' variable                                          { $$ = Expr\ArrayItem[$2, null, true]; }
987 ;
988
989 encaps_list:
990       encaps_list encaps_var                                { push($1, $2); }
991     | encaps_list encaps_string_part                        { push($1, $2); }
992     | encaps_var                                            { init($1); }
993     | encaps_string_part encaps_var                         { init($1, $2); }
994 ;
995
996 encaps_string_part:
997       T_ENCAPSED_AND_WHITESPACE                             { $$ = Scalar\EncapsedStringPart[$1]; }
998 ;
999
1000 encaps_str_varname:
1001       T_STRING_VARNAME                                      { $$ = Expr\Variable[$1]; }
1002 ;
1003
1004 encaps_var:
1005       plain_variable                                        { $$ = $1; }
1006     | plain_variable '[' encaps_var_offset ']'              { $$ = Expr\ArrayDimFetch[$1, $3]; }
1007     | plain_variable T_OBJECT_OPERATOR identifier           { $$ = Expr\PropertyFetch[$1, $3]; }
1008     | T_DOLLAR_OPEN_CURLY_BRACES expr '}'                   { $$ = Expr\Variable[$2]; }
1009     | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'       { $$ = Expr\Variable[$2]; }
1010     | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}'
1011           { $$ = Expr\ArrayDimFetch[$2, $4]; }
1012     | T_CURLY_OPEN variable '}'                             { $$ = $2; }
1013 ;
1014
1015 encaps_var_offset:
1016       T_STRING                                              { $$ = Scalar\String_[$1]; }
1017     | T_NUM_STRING                                          { $$ = $this->parseNumString($1, attributes()); }
1018     | plain_variable                                        { $$ = $1; }
1019 ;
1020
1021 %%