43d5b666d871269d294617d86cb8c88b0ad68e42
[yaffs-website] / vendor / nikic / 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_DECLARE '(' declare_list ')' declare_statement      { $$ = Stmt\Declare_[$3, $5]; }
244     | T_TRY '{' inner_statement_list '}' catches optional_finally
245           { $$ = Stmt\TryCatch[$3, $5, $6]; $this->checkTryCatch($$); }
246     | T_THROW expr semi                                     { $$ = Stmt\Throw_[$2]; }
247     | T_GOTO identifier semi                                { $$ = Stmt\Goto_[$2]; }
248     | identifier ':'                                        { $$ = Stmt\Label[$1]; }
249     | error                                                 { $$ = array(); /* means: no statement */ }
250 ;
251
252 statement:
253       non_empty_statement                                   { $$ = $1; }
254     | ';'
255           { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
256             if ($$ === null) $$ = array(); /* means: no statement */ }
257 ;
258
259 catches:
260       /* empty */                                           { init(); }
261     | catches catch                                         { push($1, $2); }
262 ;
263
264 name_union:
265       name                                                  { init($1); }
266     | name_union '|' name                                   { push($1, $3); }
267 ;
268
269 catch:
270     T_CATCH '(' name_union plain_variable ')' '{' inner_statement_list '}'
271         { $$ = Stmt\Catch_[$3, $4, $7]; }
272 ;
273
274 optional_finally:
275       /* empty */                                           { $$ = null; }
276     | T_FINALLY '{' inner_statement_list '}'                { $$ = Stmt\Finally_[$3]; }
277 ;
278
279 variables_list:
280       non_empty_variables_list optional_comma               { $$ = $1; }
281 ;
282
283 non_empty_variables_list:
284       variable                                              { init($1); }
285     | non_empty_variables_list ',' variable                 { push($1, $3); }
286 ;
287
288 optional_ref:
289       /* empty */                                           { $$ = false; }
290     | '&'                                                   { $$ = true; }
291 ;
292
293 optional_ellipsis:
294       /* empty */                                           { $$ = false; }
295     | T_ELLIPSIS                                            { $$ = true; }
296 ;
297
298 function_declaration_statement:
299     T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
300         { $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
301 ;
302
303 class_declaration_statement:
304       class_entry_type identifier extends_from implements_list '{' class_statement_list '}'
305           { $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6]];
306             $this->checkClass($$, #2); }
307     | T_INTERFACE identifier interface_extends_list '{' class_statement_list '}'
308           { $$ = Stmt\Interface_[$2, ['extends' => $3, 'stmts' => $5]];
309             $this->checkInterface($$, #2); }
310     | T_TRAIT identifier '{' class_statement_list '}'
311           { $$ = Stmt\Trait_[$2, ['stmts' => $4]]; }
312 ;
313
314 class_entry_type:
315       T_CLASS                                               { $$ = 0; }
316     | T_ABSTRACT T_CLASS                                    { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
317     | T_FINAL T_CLASS                                       { $$ = Stmt\Class_::MODIFIER_FINAL; }
318 ;
319
320 extends_from:
321       /* empty */                                           { $$ = null; }
322     | T_EXTENDS class_name                                  { $$ = $2; }
323 ;
324
325 interface_extends_list:
326       /* empty */                                           { $$ = array(); }
327     | T_EXTENDS class_name_list                             { $$ = $2; }
328 ;
329
330 implements_list:
331       /* empty */                                           { $$ = array(); }
332     | T_IMPLEMENTS class_name_list                          { $$ = $2; }
333 ;
334
335 class_name_list:
336       non_empty_class_name_list no_comma                    { $$ = $1; }
337 ;
338
339 non_empty_class_name_list:
340       class_name                                            { init($1); }
341     | non_empty_class_name_list ',' class_name              { push($1, $3); }
342 ;
343
344 for_statement:
345       statement                                             { $$ = toArray($1); }
346     | ':' inner_statement_list T_ENDFOR ';'                 { $$ = $2; }
347 ;
348
349 foreach_statement:
350       statement                                             { $$ = toArray($1); }
351     | ':' inner_statement_list T_ENDFOREACH ';'             { $$ = $2; }
352 ;
353
354 declare_statement:
355       non_empty_statement                                   { $$ = toArray($1); }
356     | ';'                                                   { $$ = null; }
357     | ':' inner_statement_list T_ENDDECLARE ';'             { $$ = $2; }
358 ;
359
360 declare_list:
361       non_empty_declare_list no_comma                       { $$ = $1; }
362 ;
363
364 non_empty_declare_list:
365       declare_list_element                                  { init($1); }
366     | non_empty_declare_list ',' declare_list_element       { push($1, $3); }
367 ;
368
369 declare_list_element:
370       identifier '=' expr                                   { $$ = Stmt\DeclareDeclare[$1, $3]; }
371 ;
372
373 switch_case_list:
374       '{' case_list '}'                                     { $$ = $2; }
375     | '{' ';' case_list '}'                                 { $$ = $3; }
376     | ':' case_list T_ENDSWITCH ';'                         { $$ = $2; }
377     | ':' ';' case_list T_ENDSWITCH ';'                     { $$ = $3; }
378 ;
379
380 case_list:
381       /* empty */                                           { init(); }
382     | case_list case                                        { push($1, $2); }
383 ;
384
385 case:
386       T_CASE expr case_separator inner_statement_list_ex    { $$ = Stmt\Case_[$2, $4]; }
387     | T_DEFAULT case_separator inner_statement_list_ex      { $$ = Stmt\Case_[null, $3]; }
388 ;
389
390 case_separator:
391       ':'
392     | ';'
393 ;
394
395 while_statement:
396       statement                                             { $$ = toArray($1); }
397     | ':' inner_statement_list T_ENDWHILE ';'               { $$ = $2; }
398 ;
399
400 elseif_list:
401       /* empty */                                           { init(); }
402     | elseif_list elseif                                    { push($1, $2); }
403 ;
404
405 elseif:
406       T_ELSEIF '(' expr ')' statement                       { $$ = Stmt\ElseIf_[$3, toArray($5)]; }
407 ;
408
409 new_elseif_list:
410       /* empty */                                           { init(); }
411     | new_elseif_list new_elseif                            { push($1, $2); }
412 ;
413
414 new_elseif:
415      T_ELSEIF '(' expr ')' ':' inner_statement_list         { $$ = Stmt\ElseIf_[$3, $6]; }
416 ;
417
418 else_single:
419       /* empty */                                           { $$ = null; }
420     | T_ELSE statement                                      { $$ = Stmt\Else_[toArray($2)]; }
421 ;
422
423 new_else_single:
424       /* empty */                                           { $$ = null; }
425     | T_ELSE ':' inner_statement_list                       { $$ = Stmt\Else_[$3]; }
426 ;
427
428 foreach_variable:
429       variable                                              { $$ = array($1, false); }
430     | '&' variable                                          { $$ = array($2, true); }
431     | list_expr                                             { $$ = array($1, false); }
432     | array_short_syntax                                    { $$ = array($1, false); }
433 ;
434
435 parameter_list:
436       non_empty_parameter_list no_comma                     { $$ = $1; }
437     | /* empty */                                           { $$ = array(); }
438 ;
439
440 non_empty_parameter_list:
441       parameter                                             { init($1); }
442     | non_empty_parameter_list ',' parameter                { push($1, $3); }
443 ;
444
445 parameter:
446       optional_param_type optional_ref optional_ellipsis plain_variable
447           { $$ = Node\Param[$4, null, $1, $2, $3]; $this->checkParam($$); }
448     | optional_param_type optional_ref optional_ellipsis plain_variable '=' expr
449           { $$ = Node\Param[$4, $6, $1, $2, $3]; $this->checkParam($$); }
450 ;
451
452 type_expr:
453       type                                                  { $$ = $1; }
454     | '?' type                                              { $$ = Node\NullableType[$2]; }
455 ;
456
457 type:
458       name                                                  { $$ = $this->handleBuiltinTypes($1); }
459     | T_ARRAY                                               { $$ = Node\Identifier['array']; }
460     | T_CALLABLE                                            { $$ = Node\Identifier['callable']; }
461 ;
462
463 optional_param_type:
464       /* empty */                                           { $$ = null; }
465     | type_expr                                             { $$ = $1; }
466 ;
467
468 optional_return_type:
469       /* empty */                                           { $$ = null; }
470     | ':' type_expr                                         { $$ = $2; }
471 ;
472
473 argument_list:
474       '(' ')'                                               { $$ = array(); }
475     | '(' non_empty_argument_list optional_comma ')'        { $$ = $2; }
476 ;
477
478 non_empty_argument_list:
479       argument                                              { init($1); }
480     | non_empty_argument_list ',' argument                  { push($1, $3); }
481 ;
482
483 argument:
484       expr                                                  { $$ = Node\Arg[$1, false, false]; }
485     | '&' variable                                          { $$ = Node\Arg[$2, true, false]; }
486     | T_ELLIPSIS expr                                       { $$ = Node\Arg[$2, false, true]; }
487 ;
488
489 global_var_list:
490       non_empty_global_var_list no_comma                    { $$ = $1; }
491 ;
492
493 non_empty_global_var_list:
494       non_empty_global_var_list ',' global_var              { push($1, $3); }
495     | global_var                                            { init($1); }
496 ;
497
498 global_var:
499       simple_variable                                       { $$ = Expr\Variable[$1]; }
500 ;
501
502 static_var_list:
503       non_empty_static_var_list no_comma                    { $$ = $1; }
504 ;
505
506 non_empty_static_var_list:
507       non_empty_static_var_list ',' static_var              { push($1, $3); }
508     | static_var                                            { init($1); }
509 ;
510
511 static_var:
512       plain_variable                                        { $$ = Stmt\StaticVar[$1, null]; }
513     | plain_variable '=' expr                               { $$ = Stmt\StaticVar[$1, $3]; }
514 ;
515
516 class_statement_list:
517       class_statement_list class_statement                  { push($1, $2); }
518     | /* empty */                                           { init(); }
519 ;
520
521 class_statement:
522       variable_modifiers property_declaration_list ';'
523           { $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); }
524     | method_modifiers T_CONST class_const_list ';'
525           { $$ = Stmt\ClassConst[$3, $1]; $this->checkClassConst($$, #1); }
526     | method_modifiers T_FUNCTION optional_ref identifier_ex '(' parameter_list ')' optional_return_type method_body
527           { $$ = Stmt\ClassMethod[$4, ['type' => $1, 'byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9]];
528             $this->checkClassMethod($$, #1); }
529     | T_USE class_name_list trait_adaptations               { $$ = Stmt\TraitUse[$2, $3]; }
530 ;
531
532 trait_adaptations:
533       ';'                                                   { $$ = array(); }
534     | '{' trait_adaptation_list '}'                         { $$ = $2; }
535 ;
536
537 trait_adaptation_list:
538       /* empty */                                           { init(); }
539     | trait_adaptation_list trait_adaptation                { push($1, $2); }
540 ;
541
542 trait_adaptation:
543       trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';'
544           { $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; }
545     | trait_method_reference T_AS member_modifier identifier_ex ';'
546           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; }
547     | trait_method_reference T_AS member_modifier ';'
548           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; }
549     | trait_method_reference T_AS identifier ';'
550           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
551     | trait_method_reference T_AS reserved_non_modifiers_identifier ';'
552           { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
553 ;
554
555 trait_method_reference_fully_qualified:
556       name T_PAAMAYIM_NEKUDOTAYIM identifier_ex             { $$ = array($1, $3); }
557 ;
558 trait_method_reference:
559       trait_method_reference_fully_qualified                { $$ = $1; }
560     | identifier_ex                                         { $$ = array(null, $1); }
561 ;
562
563 method_body:
564       ';' /* abstract method */                             { $$ = null; }
565     | '{' inner_statement_list '}'                          { $$ = $2; }
566 ;
567
568 variable_modifiers:
569       non_empty_member_modifiers                            { $$ = $1; }
570     | T_VAR                                                 { $$ = 0; }
571 ;
572
573 method_modifiers:
574       /* empty */                                           { $$ = 0; }
575     | non_empty_member_modifiers                            { $$ = $1; }
576 ;
577
578 non_empty_member_modifiers:
579       member_modifier                                       { $$ = $1; }
580     | non_empty_member_modifiers member_modifier            { $this->checkModifier($1, $2, #2); $$ = $1 | $2; }
581 ;
582
583 member_modifier:
584       T_PUBLIC                                              { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
585     | T_PROTECTED                                           { $$ = Stmt\Class_::MODIFIER_PROTECTED; }
586     | T_PRIVATE                                             { $$ = Stmt\Class_::MODIFIER_PRIVATE; }
587     | T_STATIC                                              { $$ = Stmt\Class_::MODIFIER_STATIC; }
588     | T_ABSTRACT                                            { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
589     | T_FINAL                                               { $$ = Stmt\Class_::MODIFIER_FINAL; }
590 ;
591
592 property_declaration_list:
593       non_empty_property_declaration_list no_comma          { $$ = $1; }
594 ;
595
596 non_empty_property_declaration_list:
597       property_declaration                                  { init($1); }
598     | non_empty_property_declaration_list ',' property_declaration
599           { push($1, $3); }
600 ;
601
602 property_decl_name:
603       T_VARIABLE                                            { $$ = Node\VarLikeIdentifier[parseVar($1)]; }
604 ;
605
606 property_declaration:
607       property_decl_name                                    { $$ = Stmt\PropertyProperty[$1, null]; }
608     | property_decl_name '=' expr                           { $$ = Stmt\PropertyProperty[$1, $3]; }
609 ;
610
611 expr_list:
612       non_empty_expr_list no_comma                          { $$ = $1; }
613 ;
614
615 non_empty_expr_list:
616       non_empty_expr_list ',' expr                          { push($1, $3); }
617     | expr                                                  { init($1); }
618 ;
619
620 for_expr:
621       /* empty */                                           { $$ = array(); }
622     | expr_list                                             { $$ = $1; }
623 ;
624
625 expr:
626       variable                                              { $$ = $1; }
627     | list_expr '=' expr                                    { $$ = Expr\Assign[$1, $3]; }
628     | array_short_syntax '=' expr                           { $$ = Expr\Assign[$1, $3]; }
629     | variable '=' expr                                     { $$ = Expr\Assign[$1, $3]; }
630     | variable '=' '&' variable                             { $$ = Expr\AssignRef[$1, $4]; }
631     | new_expr                                              { $$ = $1; }
632     | T_CLONE expr                                          { $$ = Expr\Clone_[$2]; }
633     | variable T_PLUS_EQUAL expr                            { $$ = Expr\AssignOp\Plus      [$1, $3]; }
634     | variable T_MINUS_EQUAL expr                           { $$ = Expr\AssignOp\Minus     [$1, $3]; }
635     | variable T_MUL_EQUAL expr                             { $$ = Expr\AssignOp\Mul       [$1, $3]; }
636     | variable T_DIV_EQUAL expr                             { $$ = Expr\AssignOp\Div       [$1, $3]; }
637     | variable T_CONCAT_EQUAL expr                          { $$ = Expr\AssignOp\Concat    [$1, $3]; }
638     | variable T_MOD_EQUAL expr                             { $$ = Expr\AssignOp\Mod       [$1, $3]; }
639     | variable T_AND_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseAnd[$1, $3]; }
640     | variable T_OR_EQUAL expr                              { $$ = Expr\AssignOp\BitwiseOr [$1, $3]; }
641     | variable T_XOR_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseXor[$1, $3]; }
642     | variable T_SL_EQUAL expr                              { $$ = Expr\AssignOp\ShiftLeft [$1, $3]; }
643     | variable T_SR_EQUAL expr                              { $$ = Expr\AssignOp\ShiftRight[$1, $3]; }
644     | variable T_POW_EQUAL expr                             { $$ = Expr\AssignOp\Pow       [$1, $3]; }
645     | variable T_INC                                        { $$ = Expr\PostInc[$1]; }
646     | T_INC variable                                        { $$ = Expr\PreInc [$2]; }
647     | variable T_DEC                                        { $$ = Expr\PostDec[$1]; }
648     | T_DEC variable                                        { $$ = Expr\PreDec [$2]; }
649     | expr T_BOOLEAN_OR expr                                { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; }
650     | expr T_BOOLEAN_AND expr                               { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; }
651     | expr T_LOGICAL_OR expr                                { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; }
652     | expr T_LOGICAL_AND expr                               { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; }
653     | expr T_LOGICAL_XOR expr                               { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; }
654     | expr '|' expr                                         { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; }
655     | expr '&' expr                                         { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
656     | expr '^' expr                                         { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; }
657     | expr '.' expr                                         { $$ = Expr\BinaryOp\Concat    [$1, $3]; }
658     | expr '+' expr                                         { $$ = Expr\BinaryOp\Plus      [$1, $3]; }
659     | expr '-' expr                                         { $$ = Expr\BinaryOp\Minus     [$1, $3]; }
660     | expr '*' expr                                         { $$ = Expr\BinaryOp\Mul       [$1, $3]; }
661     | expr '/' expr                                         { $$ = Expr\BinaryOp\Div       [$1, $3]; }
662     | expr '%' expr                                         { $$ = Expr\BinaryOp\Mod       [$1, $3]; }
663     | expr T_SL expr                                        { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; }
664     | expr T_SR expr                                        { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; }
665     | expr T_POW expr                                       { $$ = Expr\BinaryOp\Pow       [$1, $3]; }
666     | '+' expr %prec T_INC                                  { $$ = Expr\UnaryPlus [$2]; }
667     | '-' expr %prec T_INC                                  { $$ = Expr\UnaryMinus[$2]; }
668     | '!' expr                                              { $$ = Expr\BooleanNot[$2]; }
669     | '~' expr                                              { $$ = Expr\BitwiseNot[$2]; }
670     | expr T_IS_IDENTICAL expr                              { $$ = Expr\BinaryOp\Identical     [$1, $3]; }
671     | expr T_IS_NOT_IDENTICAL expr                          { $$ = Expr\BinaryOp\NotIdentical  [$1, $3]; }
672     | expr T_IS_EQUAL expr                                  { $$ = Expr\BinaryOp\Equal         [$1, $3]; }
673     | expr T_IS_NOT_EQUAL expr                              { $$ = Expr\BinaryOp\NotEqual      [$1, $3]; }
674     | expr T_SPACESHIP expr                                 { $$ = Expr\BinaryOp\Spaceship     [$1, $3]; }
675     | expr '<' expr                                         { $$ = Expr\BinaryOp\Smaller       [$1, $3]; }
676     | expr T_IS_SMALLER_OR_EQUAL expr                       { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; }
677     | expr '>' expr                                         { $$ = Expr\BinaryOp\Greater       [$1, $3]; }
678     | expr T_IS_GREATER_OR_EQUAL expr                       { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; }
679     | expr T_INSTANCEOF class_name_reference                { $$ = Expr\Instanceof_[$1, $3]; }
680     | '(' expr ')'                                          { $$ = $2; }
681     | expr '?' expr ':' expr                                { $$ = Expr\Ternary[$1, $3,   $5]; }
682     | expr '?' ':' expr                                     { $$ = Expr\Ternary[$1, null, $4]; }
683     | expr T_COALESCE expr                                  { $$ = Expr\BinaryOp\Coalesce[$1, $3]; }
684     | T_ISSET '(' variables_list ')'                        { $$ = Expr\Isset_[$3]; }
685     | T_EMPTY '(' expr ')'                                  { $$ = Expr\Empty_[$3]; }
686     | T_INCLUDE expr                                        { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; }
687     | T_INCLUDE_ONCE expr                                   { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; }
688     | T_EVAL '(' expr ')'                                   { $$ = Expr\Eval_[$3]; }
689     | T_REQUIRE expr                                        { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE]; }
690     | T_REQUIRE_ONCE expr                                   { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE_ONCE]; }
691     | T_INT_CAST expr                                       { $$ = Expr\Cast\Int_    [$2]; }
692     | T_DOUBLE_CAST expr                                    { $$ = Expr\Cast\Double  [$2]; }
693     | T_STRING_CAST expr                                    { $$ = Expr\Cast\String_ [$2]; }
694     | T_ARRAY_CAST expr                                     { $$ = Expr\Cast\Array_  [$2]; }
695     | T_OBJECT_CAST expr                                    { $$ = Expr\Cast\Object_ [$2]; }
696     | T_BOOL_CAST expr                                      { $$ = Expr\Cast\Bool_   [$2]; }
697     | T_UNSET_CAST expr                                     { $$ = Expr\Cast\Unset_  [$2]; }
698     | T_EXIT exit_expr
699           { $attrs = attributes();
700             $attrs['kind'] = strtolower($1) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE;
701             $$ = new Expr\Exit_($2, $attrs); }
702     | '@' expr                                              { $$ = Expr\ErrorSuppress[$2]; }
703     | scalar                                                { $$ = $1; }
704     | '`' backticks_expr '`'                                { $$ = Expr\ShellExec[$2]; }
705     | T_PRINT expr                                          { $$ = Expr\Print_[$2]; }
706     | T_YIELD                                               { $$ = Expr\Yield_[null, null]; }
707     | T_YIELD expr                                          { $$ = Expr\Yield_[$2, null]; }
708     | T_YIELD expr T_DOUBLE_ARROW expr                      { $$ = Expr\Yield_[$4, $2]; }
709     | T_YIELD_FROM expr                                     { $$ = Expr\YieldFrom[$2]; }
710     | T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
711       '{' inner_statement_list '}'
712           { $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $9]]; }
713     | T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
714       '{' inner_statement_list '}'
715           { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $10]]; }
716 ;
717
718 anonymous_class:
719       T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
720           { $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $3, 'implements' => $4, 'stmts' => $6]], $2);
721             $this->checkClass($$[0], -1); }
722 ;
723
724 new_expr:
725       T_NEW class_name_reference ctor_arguments             { $$ = Expr\New_[$2, $3]; }
726     | T_NEW anonymous_class
727           { list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; }
728 ;
729
730 lexical_vars:
731       /* empty */                                           { $$ = array(); }
732     | T_USE '(' lexical_var_list ')'                        { $$ = $3; }
733 ;
734
735 lexical_var_list:
736       non_empty_lexical_var_list no_comma                   { $$ = $1; }
737 ;
738
739 non_empty_lexical_var_list:
740       lexical_var                                           { init($1); }
741     | non_empty_lexical_var_list ',' lexical_var            { push($1, $3); }
742 ;
743
744 lexical_var:
745       optional_ref plain_variable                           { $$ = Expr\ClosureUse[$2, $1]; }
746 ;
747
748 function_call:
749       name argument_list                                    { $$ = Expr\FuncCall[$1, $2]; }
750     | callable_expr argument_list                           { $$ = Expr\FuncCall[$1, $2]; }
751     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
752           { $$ = Expr\StaticCall[$1, $3, $4]; }
753 ;
754
755 class_name:
756       T_STATIC                                              { $$ = Name[$1]; }
757     | name                                                  { $$ = $1; }
758 ;
759
760 name:
761       namespace_name_parts                                  { $$ = Name[$1]; }
762     | T_NS_SEPARATOR namespace_name_parts                   { $$ = Name\FullyQualified[$2]; }
763     | T_NAMESPACE T_NS_SEPARATOR namespace_name_parts       { $$ = Name\Relative[$3]; }
764 ;
765
766 class_name_reference:
767       class_name                                            { $$ = $1; }
768     | new_variable                                          { $$ = $1; }
769     | error                                                 { $$ = Expr\Error[]; $this->errorState = 2; }
770 ;
771
772 class_name_or_var:
773       class_name                                            { $$ = $1; }
774     | dereferencable                                        { $$ = $1; }
775 ;
776
777 exit_expr:
778       /* empty */                                           { $$ = null; }
779     | '(' optional_expr ')'                                 { $$ = $2; }
780 ;
781
782 backticks_expr:
783       /* empty */                                           { $$ = array(); }
784     | T_ENCAPSED_AND_WHITESPACE
785           { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`')]); }
786     | encaps_list                                           { parseEncapsed($1, '`', true); $$ = $1; }
787 ;
788
789 ctor_arguments:
790       /* empty */                                           { $$ = array(); }
791     | argument_list                                         { $$ = $1; }
792 ;
793
794 constant:
795       name                                                  { $$ = Expr\ConstFetch[$1]; }
796     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex
797           { $$ = Expr\ClassConstFetch[$1, $3]; }
798     /* We interpret and isolated FOO:: as an unfinished class constant fetch. It could also be
799        an unfinished static property fetch or unfinished scoped call. */
800     | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM error
801           { $$ = Expr\ClassConstFetch[$1, new Expr\Error(stackAttributes(#3))]; $this->errorState = 2; }
802 ;
803
804 array_short_syntax:
805       '[' array_pair_list ']'
806           { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT;
807             $$ = new Expr\Array_($2, $attrs); }
808 ;
809
810 dereferencable_scalar:
811       T_ARRAY '(' array_pair_list ')'
812           { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG;
813             $$ = new Expr\Array_($3, $attrs); }
814     | array_short_syntax                                    { $$ = $1; }
815     | T_CONSTANT_ENCAPSED_STRING
816           { $attrs = attributes(); $attrs['kind'] = strKind($1);
817             $$ = new Scalar\String_(Scalar\String_::parse($1), $attrs); }
818 ;
819
820 scalar:
821       T_LNUMBER                                             { $$ = $this->parseLNumber($1, attributes()); }
822     | T_DNUMBER                                             { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; }
823     | T_LINE                                                { $$ = Scalar\MagicConst\Line[]; }
824     | T_FILE                                                { $$ = Scalar\MagicConst\File[]; }
825     | T_DIR                                                 { $$ = Scalar\MagicConst\Dir[]; }
826     | T_CLASS_C                                             { $$ = Scalar\MagicConst\Class_[]; }
827     | T_TRAIT_C                                             { $$ = Scalar\MagicConst\Trait_[]; }
828     | T_METHOD_C                                            { $$ = Scalar\MagicConst\Method[]; }
829     | T_FUNC_C                                              { $$ = Scalar\MagicConst\Function_[]; }
830     | T_NS_C                                                { $$ = Scalar\MagicConst\Namespace_[]; }
831     | dereferencable_scalar                                 { $$ = $1; }
832     | constant                                              { $$ = $1; }
833     | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
834           { $attrs = attributes(); setDocStringAttrs($attrs, $1);
835             $$ = new Scalar\String_(Scalar\String_::parseDocString($1, $2), $attrs); }
836     | T_START_HEREDOC T_END_HEREDOC
837           { $attrs = attributes(); setDocStringAttrs($attrs, $1);
838             $$ = new Scalar\String_('', $attrs); }
839     | '"' encaps_list '"'
840           { $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED;
841             parseEncapsed($2, '"', true); $$ = new Scalar\Encapsed($2, $attrs); }
842     | T_START_HEREDOC encaps_list T_END_HEREDOC
843           { $attrs = attributes(); setDocStringAttrs($attrs, $1);
844             parseEncapsedDoc($2, true); $$ = new Scalar\Encapsed($2, $attrs); }
845 ;
846
847 optional_expr:
848       /* empty */                                           { $$ = null; }
849     | expr                                                  { $$ = $1; }
850 ;
851
852 dereferencable:
853       variable                                              { $$ = $1; }
854     | '(' expr ')'                                          { $$ = $2; }
855     | dereferencable_scalar                                 { $$ = $1; }
856 ;
857
858 callable_expr:
859       callable_variable                                     { $$ = $1; }
860     | '(' expr ')'                                          { $$ = $2; }
861     | dereferencable_scalar                                 { $$ = $1; }
862 ;
863
864 callable_variable:
865       simple_variable                                       { $$ = Expr\Variable[$1]; }
866     | dereferencable '[' optional_expr ']'                  { $$ = Expr\ArrayDimFetch[$1, $3]; }
867     | constant '[' optional_expr ']'                        { $$ = Expr\ArrayDimFetch[$1, $3]; }
868     | dereferencable '{' expr '}'                           { $$ = Expr\ArrayDimFetch[$1, $3]; }
869     | function_call                                         { $$ = $1; }
870     | dereferencable T_OBJECT_OPERATOR property_name argument_list
871           { $$ = Expr\MethodCall[$1, $3, $4]; }
872 ;
873
874 variable:
875       callable_variable                                     { $$ = $1; }
876     | static_member                                         { $$ = $1; }
877     | dereferencable T_OBJECT_OPERATOR property_name        { $$ = Expr\PropertyFetch[$1, $3]; }
878 ;
879
880 simple_variable:
881       T_VARIABLE                                            { $$ = parseVar($1); }
882     | '$' '{' expr '}'                                      { $$ = $3; }
883     | '$' simple_variable                                   { $$ = Expr\Variable[$2]; }
884     | '$' error                                             { $$ = Expr\Error[]; $this->errorState = 2; }
885 ;
886
887 static_member_prop_name:
888       simple_variable
889           { $var = $1; $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; }
890 ;
891
892 static_member:
893       class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name
894           { $$ = Expr\StaticPropertyFetch[$1, $3]; }
895 ;
896
897 new_variable:
898       simple_variable                                       { $$ = Expr\Variable[$1]; }
899     | new_variable '[' optional_expr ']'                    { $$ = Expr\ArrayDimFetch[$1, $3]; }
900     | new_variable '{' expr '}'                             { $$ = Expr\ArrayDimFetch[$1, $3]; }
901     | new_variable T_OBJECT_OPERATOR property_name          { $$ = Expr\PropertyFetch[$1, $3]; }
902     | class_name T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name
903           { $$ = Expr\StaticPropertyFetch[$1, $3]; }
904     | new_variable T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name
905           { $$ = Expr\StaticPropertyFetch[$1, $3]; }
906 ;
907
908 member_name:
909       identifier_ex                                         { $$ = $1; }
910     | '{' expr '}'                                              { $$ = $2; }
911     | simple_variable                                       { $$ = Expr\Variable[$1]; }
912 ;
913
914 property_name:
915       identifier                                            { $$ = $1; }
916     | '{' expr '}'                                              { $$ = $2; }
917     | simple_variable                                       { $$ = Expr\Variable[$1]; }
918     | error                                                 { $$ = Expr\Error[]; $this->errorState = 2; }
919 ;
920
921 list_expr:
922       T_LIST '(' list_expr_elements ')'                     { $$ = Expr\List_[$3]; }
923 ;
924
925 list_expr_elements:
926       list_expr_elements ',' list_expr_element              { push($1, $3); }
927     | list_expr_element                                     { init($1); }
928 ;
929
930 list_expr_element:
931       variable                                              { $$ = Expr\ArrayItem[$1, null, false]; }
932     | '&' variable                                          { $$ = Expr\ArrayItem[$2, null, true]; }
933     | list_expr                                             { $$ = Expr\ArrayItem[$1, null, false]; }
934     | expr T_DOUBLE_ARROW variable                          { $$ = Expr\ArrayItem[$3, $1, false]; }
935     | expr T_DOUBLE_ARROW '&' variable                      { $$ = Expr\ArrayItem[$4, $1, true]; }
936     | expr T_DOUBLE_ARROW list_expr                         { $$ = Expr\ArrayItem[$3, $1, false]; }
937     | /* empty */                                           { $$ = null; }
938 ;
939
940 array_pair_list:
941       inner_array_pair_list
942           { $$ = $1; $end = count($$)-1; if ($$[$end] === null) array_pop($$); }
943 ;
944
945 inner_array_pair_list:
946       inner_array_pair_list ',' array_pair                  { push($1, $3); }
947     | array_pair                                            { init($1); }
948 ;
949
950 array_pair:
951       expr T_DOUBLE_ARROW expr                              { $$ = Expr\ArrayItem[$3, $1,   false]; }
952     | expr                                                  { $$ = Expr\ArrayItem[$1, null, false]; }
953     | expr T_DOUBLE_ARROW '&' variable                      { $$ = Expr\ArrayItem[$4, $1,   true]; }
954     | '&' variable                                          { $$ = Expr\ArrayItem[$2, null, true]; }
955     | /* empty */                                           { $$ = null; }
956 ;
957
958 encaps_list:
959       encaps_list encaps_var                                { push($1, $2); }
960     | encaps_list encaps_string_part                        { push($1, $2); }
961     | encaps_var                                            { init($1); }
962     | encaps_string_part encaps_var                         { init($1, $2); }
963 ;
964
965 encaps_string_part:
966       T_ENCAPSED_AND_WHITESPACE                             { $$ = Scalar\EncapsedStringPart[$1]; }
967 ;
968
969 encaps_str_varname:
970       T_STRING_VARNAME                                      { $$ = Expr\Variable[$1]; }
971 ;
972
973 encaps_var:
974       plain_variable                                        { $$ = $1; }
975     | plain_variable '[' encaps_var_offset ']'              { $$ = Expr\ArrayDimFetch[$1, $3]; }
976     | plain_variable T_OBJECT_OPERATOR identifier           { $$ = Expr\PropertyFetch[$1, $3]; }
977     | T_DOLLAR_OPEN_CURLY_BRACES expr '}'                   { $$ = Expr\Variable[$2]; }
978     | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'       { $$ = Expr\Variable[$2]; }
979     | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}'
980           { $$ = Expr\ArrayDimFetch[$2, $4]; }
981     | T_CURLY_OPEN variable '}'                             { $$ = $2; }
982 ;
983
984 encaps_var_offset:
985       T_STRING                                              { $$ = Scalar\String_[$1]; }
986     | T_NUM_STRING                                          { $$ = $this->parseNumString($1, attributes()); }
987     | '-' T_NUM_STRING                                      { $$ = $this->parseNumString('-' . $2, attributes()); }
988     | plain_variable                                        { $$ = $1; }
989 ;
990
991 %%