9 top_statement_list { $$ = $this->handleNamespaces($1); }
12 top_statement_list_ex:
13 top_statement_list_ex top_statement { pushNormalizing($1, $2); }
14 | /* empty */ { init(); }
19 { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
20 if ($nop !== null) { $1[] = $nop; } $$ = $1; }
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
34 reserved_non_modifiers
35 | T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
39 T_STRING { $$ = Node\Identifier[$1]; }
40 | semi_reserved { $$ = Node\Identifier[$1]; }
44 T_STRING { $$ = Node\Identifier[$1]; }
47 reserved_non_modifiers_identifier:
48 reserved_non_modifiers { $$ = Node\Identifier[$1]; }
52 T_STRING { init($1); }
53 | namespace_name_parts T_NS_SEPARATOR T_STRING { push($1, $3); }
57 namespace_name_parts { $$ = Name[$1]; }
61 T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
66 | error { /* nothing */ }
70 /* empty */ { /* nothing */ }
71 | ',' { $this->emitError(new Error('A trailing comma is not allowed here', attributes())); }
79 statement { $$ = $1; }
80 | function_declaration_statement { $$ = $1; }
81 | class_declaration_statement { $$ = $1; }
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]; }
103 T_FUNCTION { $$ = Stmt\Use_::TYPE_FUNCTION; }
104 | T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; }
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]; }
119 unprefixed_use_declarations:
120 non_empty_unprefixed_use_declarations optional_comma { $$ = $1; }
123 non_empty_unprefixed_use_declarations:
124 non_empty_unprefixed_use_declarations ',' unprefixed_use_declaration
126 | unprefixed_use_declaration { init($1); }
130 non_empty_use_declarations no_comma { $$ = $1; }
133 non_empty_use_declarations:
134 non_empty_use_declarations ',' use_declaration { push($1, $3); }
135 | use_declaration { init($1); }
138 inline_use_declarations:
139 non_empty_inline_use_declarations optional_comma { $$ = $1; }
142 non_empty_inline_use_declarations:
143 non_empty_inline_use_declarations ',' inline_use_declaration
145 | inline_use_declaration { init($1); }
148 unprefixed_use_declaration:
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); }
156 unprefixed_use_declaration { $$ = $1; }
157 | T_NS_SEPARATOR unprefixed_use_declaration { $$ = $2; }
160 inline_use_declaration:
161 unprefixed_use_declaration { $$ = $1; $$->type = Stmt\Use_::TYPE_NORMAL; }
162 | use_type unprefixed_use_declaration { $$ = $2; $$->type = $1; }
165 constant_declaration_list:
166 non_empty_constant_declaration_list no_comma { $$ = $1; }
169 non_empty_constant_declaration_list:
170 non_empty_constant_declaration_list ',' constant_declaration
172 | constant_declaration { init($1); }
175 constant_declaration:
176 identifier '=' expr { $$ = Node\Const_[$1, $3]; }
180 non_empty_class_const_list no_comma { $$ = $1; }
183 non_empty_class_const_list:
184 non_empty_class_const_list ',' class_const { push($1, $3); }
185 | class_const { init($1); }
189 identifier_ex '=' expr { $$ = Node\Const_[$1, $3]; }
192 inner_statement_list_ex:
193 inner_statement_list_ex inner_statement { pushNormalizing($1, $2); }
194 | /* empty */ { init(); }
197 inner_statement_list:
198 inner_statement_list_ex
199 { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
200 if ($nop !== null) { $1[] = $nop; } $$ = $1; }
204 statement { $$ = $1; }
205 | function_declaration_statement { $$ = $1; }
206 | class_declaration_statement { $$ = $1; }
208 { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); }
212 '{' inner_statement_list '}'
215 $$ = $2; prependLeadingComments($$);
217 makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
218 if (null === $$) { $$ = array(); }
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 */ }
255 non_empty_statement { $$ = $1; }
257 { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
258 if ($$ === null) $$ = array(); /* means: no statement */ }
262 /* empty */ { init(); }
263 | catches catch { push($1, $2); }
268 | name_union '|' name { push($1, $3); }
272 T_CATCH '(' name_union plain_variable ')' '{' inner_statement_list '}'
273 { $$ = Stmt\Catch_[$3, $4, $7]; }
277 /* empty */ { $$ = null; }
278 | T_FINALLY '{' inner_statement_list '}' { $$ = Stmt\Finally_[$3]; }
282 non_empty_variables_list optional_comma { $$ = $1; }
285 non_empty_variables_list:
286 variable { init($1); }
287 | non_empty_variables_list ',' variable { push($1, $3); }
291 /* empty */ { $$ = false; }
296 /* empty */ { $$ = false; }
297 | T_ELLIPSIS { $$ = true; }
301 '{' inner_statement_list '}' { $$ = $2; }
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]]; }
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]]; }
323 | T_ABSTRACT T_CLASS { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
324 | T_FINAL T_CLASS { $$ = Stmt\Class_::MODIFIER_FINAL; }
328 /* empty */ { $$ = null; }
329 | T_EXTENDS class_name { $$ = $2; }
332 interface_extends_list:
333 /* empty */ { $$ = array(); }
334 | T_EXTENDS class_name_list { $$ = $2; }
338 /* empty */ { $$ = array(); }
339 | T_IMPLEMENTS class_name_list { $$ = $2; }
343 non_empty_class_name_list no_comma { $$ = $1; }
346 non_empty_class_name_list:
347 class_name { init($1); }
348 | non_empty_class_name_list ',' class_name { push($1, $3); }
352 statement { $$ = toArray($1); }
353 | ':' inner_statement_list T_ENDFOR ';' { $$ = $2; }
357 statement { $$ = toArray($1); }
358 | ':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; }
362 non_empty_statement { $$ = toArray($1); }
364 | ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; }
368 non_empty_declare_list no_comma { $$ = $1; }
371 non_empty_declare_list:
372 declare_list_element { init($1); }
373 | non_empty_declare_list ',' declare_list_element { push($1, $3); }
376 declare_list_element:
377 identifier '=' expr { $$ = Stmt\DeclareDeclare[$1, $3]; }
381 '{' case_list '}' { $$ = $2; }
382 | '{' ';' case_list '}' { $$ = $3; }
383 | ':' case_list T_ENDSWITCH ';' { $$ = $2; }
384 | ':' ';' case_list T_ENDSWITCH ';' { $$ = $3; }
388 /* empty */ { init(); }
389 | case_list case { push($1, $2); }
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]; }
403 statement { $$ = toArray($1); }
404 | ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; }
408 /* empty */ { init(); }
409 | elseif_list elseif { push($1, $2); }
413 T_ELSEIF '(' expr ')' statement { $$ = Stmt\ElseIf_[$3, toArray($5)]; }
417 /* empty */ { init(); }
418 | new_elseif_list new_elseif { push($1, $2); }
422 T_ELSEIF '(' expr ')' ':' inner_statement_list { $$ = Stmt\ElseIf_[$3, $6]; }
426 /* empty */ { $$ = null; }
427 | T_ELSE statement { $$ = Stmt\Else_[toArray($2)]; }
431 /* empty */ { $$ = null; }
432 | T_ELSE ':' inner_statement_list { $$ = Stmt\Else_[$3]; }
436 variable { $$ = array($1, false); }
437 | '&' variable { $$ = array($2, true); }
438 | list_expr { $$ = array($1, false); }
439 | array_short_syntax { $$ = array($1, false); }
443 non_empty_parameter_list no_comma { $$ = $1; }
444 | /* empty */ { $$ = array(); }
447 non_empty_parameter_list:
448 parameter { init($1); }
449 | non_empty_parameter_list ',' parameter { push($1, $3); }
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]; }
463 | '?' type { $$ = Node\NullableType[$2]; }
467 name { $$ = $this->handleBuiltinTypes($1); }
468 | T_ARRAY { $$ = Node\Identifier['array']; }
469 | T_CALLABLE { $$ = Node\Identifier['callable']; }
473 /* empty */ { $$ = null; }
474 | type_expr { $$ = $1; }
477 optional_return_type:
478 /* empty */ { $$ = null; }
479 | ':' type_expr { $$ = $2; }
483 '(' ')' { $$ = array(); }
484 | '(' non_empty_argument_list optional_comma ')' { $$ = $2; }
487 non_empty_argument_list:
488 argument { init($1); }
489 | non_empty_argument_list ',' argument { push($1, $3); }
493 expr { $$ = Node\Arg[$1, false, false]; }
494 | '&' variable { $$ = Node\Arg[$2, true, false]; }
495 | T_ELLIPSIS expr { $$ = Node\Arg[$2, false, true]; }
499 non_empty_global_var_list no_comma { $$ = $1; }
502 non_empty_global_var_list:
503 non_empty_global_var_list ',' global_var { push($1, $3); }
504 | global_var { init($1); }
508 simple_variable { $$ = Expr\Variable[$1]; }
512 non_empty_static_var_list no_comma { $$ = $1; }
515 non_empty_static_var_list:
516 non_empty_static_var_list ',' static_var { push($1, $3); }
517 | static_var { init($1); }
521 plain_variable { $$ = Stmt\StaticVar[$1, null]; }
522 | plain_variable '=' expr { $$ = Stmt\StaticVar[$1, $3]; }
525 class_statement_list_ex:
526 class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } }
527 | /* empty */ { init(); }
530 class_statement_list:
531 class_statement_list_ex
532 { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
533 if ($nop !== null) { $1[] = $nop; } $$ = $1; }
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 */ }
549 ';' { $$ = array(); }
550 | '{' trait_adaptation_list '}' { $$ = $2; }
553 trait_adaptation_list:
554 /* empty */ { init(); }
555 | trait_adaptation_list trait_adaptation { push($1, $2); }
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]; }
571 trait_method_reference_fully_qualified:
572 name T_PAAMAYIM_NEKUDOTAYIM identifier_ex { $$ = array($1, $3); }
574 trait_method_reference:
575 trait_method_reference_fully_qualified { $$ = $1; }
576 | identifier_ex { $$ = array(null, $1); }
580 ';' /* abstract method */ { $$ = null; }
581 | block_or_error { $$ = $1; }
585 non_empty_member_modifiers { $$ = $1; }
590 /* empty */ { $$ = 0; }
591 | non_empty_member_modifiers { $$ = $1; }
594 non_empty_member_modifiers:
595 member_modifier { $$ = $1; }
596 | non_empty_member_modifiers member_modifier { $this->checkModifier($1, $2, #2); $$ = $1 | $2; }
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; }
608 property_declaration_list:
609 non_empty_property_declaration_list no_comma { $$ = $1; }
612 non_empty_property_declaration_list:
613 property_declaration { init($1); }
614 | non_empty_property_declaration_list ',' property_declaration
619 T_VARIABLE { $$ = Node\VarLikeIdentifier[parseVar($1)]; }
622 property_declaration:
623 property_decl_name { $$ = Stmt\PropertyProperty[$1, null]; }
624 | property_decl_name '=' expr { $$ = Stmt\PropertyProperty[$1, $3]; }
628 non_empty_expr_list no_comma { $$ = $1; }
632 non_empty_expr_list ',' expr { push($1, $3); }
637 /* empty */ { $$ = array(); }
638 | expr_list { $$ = $1; }
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]; }
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
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
731 { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $9]]; }
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); }
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]; }
747 /* empty */ { $$ = array(); }
748 | T_USE '(' lexical_var_list ')' { $$ = $3; }
752 non_empty_lexical_var_list no_comma { $$ = $1; }
755 non_empty_lexical_var_list:
756 lexical_var { init($1); }
757 | non_empty_lexical_var_list ',' lexical_var { push($1, $3); }
761 optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; }
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]; }
772 T_STATIC { $$ = Name[$1]; }
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]; }
782 class_name_reference:
783 class_name { $$ = $1; }
784 | new_variable { $$ = $1; }
785 | error { $$ = Expr\Error[]; $this->errorState = 2; }
789 class_name { $$ = $1; }
790 | dereferencable { $$ = $1; }
794 /* empty */ { $$ = null; }
795 | '(' optional_expr ')' { $$ = $2; }
799 /* empty */ { $$ = array(); }
800 | T_ENCAPSED_AND_WHITESPACE
801 { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`')]); }
802 | encaps_list { parseEncapsed($1, '`', true); $$ = $1; }
806 /* empty */ { $$ = array(); }
807 | argument_list { $$ = $1; }
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; }
821 '[' array_pair_list ']'
822 { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT;
823 $$ = new Expr\Array_($2, $attrs); }
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); }
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); }
861 /* empty */ { $$ = null; }
866 variable { $$ = $1; }
867 | '(' expr ')' { $$ = $2; }
868 | dereferencable_scalar { $$ = $1; }
872 callable_variable { $$ = $1; }
873 | '(' expr ')' { $$ = $2; }
874 | dereferencable_scalar { $$ = $1; }
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]; }
888 callable_variable { $$ = $1; }
889 | static_member { $$ = $1; }
890 | dereferencable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; }
894 T_VARIABLE { $$ = parseVar($1); }
895 | '$' '{' expr '}' { $$ = $3; }
896 | '$' simple_variable { $$ = Expr\Variable[$2]; }
897 | '$' error { $$ = Expr\Error[]; $this->errorState = 2; }
900 static_member_prop_name:
902 { $var = $1; $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; }
906 class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name
907 { $$ = Expr\StaticPropertyFetch[$1, $3]; }
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]; }
922 identifier_ex { $$ = $1; }
923 | '{' expr '}' { $$ = $2; }
924 | simple_variable { $$ = Expr\Variable[$1]; }
928 identifier { $$ = $1; }
929 | '{' expr '}' { $$ = $2; }
930 | simple_variable { $$ = Expr\Variable[$1]; }
931 | error { $$ = Expr\Error[]; $this->errorState = 2; }
935 T_LIST '(' list_expr_elements ')' { $$ = Expr\List_[$3]; }
939 list_expr_elements ',' list_expr_element { push($1, $3); }
940 | list_expr_element { init($1); }
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; }
954 inner_array_pair_list
955 { $$ = $1; $end = count($$)-1; if ($$[$end] === null) array_pop($$); }
963 inner_array_pair_list:
964 inner_array_pair_list comma_or_error array_pair { push($1, $3); }
965 | array_pair { init($1); }
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; }
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); }
984 T_ENCAPSED_AND_WHITESPACE { $$ = Scalar\EncapsedStringPart[$1]; }
988 T_STRING_VARNAME { $$ = Expr\Variable[$1]; }
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; }
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; }