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