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_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 */ }
253 non_empty_statement { $$ = $1; }
255 { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
256 if ($$ === null) $$ = array(); /* means: no statement */ }
260 /* empty */ { init(); }
261 | catches catch { push($1, $2); }
266 | name_union '|' name { push($1, $3); }
270 T_CATCH '(' name_union plain_variable ')' '{' inner_statement_list '}'
271 { $$ = Stmt\Catch_[$3, $4, $7]; }
275 /* empty */ { $$ = null; }
276 | T_FINALLY '{' inner_statement_list '}' { $$ = Stmt\Finally_[$3]; }
280 non_empty_variables_list optional_comma { $$ = $1; }
283 non_empty_variables_list:
284 variable { init($1); }
285 | non_empty_variables_list ',' variable { push($1, $3); }
289 /* empty */ { $$ = false; }
294 /* empty */ { $$ = false; }
295 | T_ELLIPSIS { $$ = true; }
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]]; }
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]]; }
316 | T_ABSTRACT T_CLASS { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
317 | T_FINAL T_CLASS { $$ = Stmt\Class_::MODIFIER_FINAL; }
321 /* empty */ { $$ = null; }
322 | T_EXTENDS class_name { $$ = $2; }
325 interface_extends_list:
326 /* empty */ { $$ = array(); }
327 | T_EXTENDS class_name_list { $$ = $2; }
331 /* empty */ { $$ = array(); }
332 | T_IMPLEMENTS class_name_list { $$ = $2; }
336 non_empty_class_name_list no_comma { $$ = $1; }
339 non_empty_class_name_list:
340 class_name { init($1); }
341 | non_empty_class_name_list ',' class_name { push($1, $3); }
345 statement { $$ = toArray($1); }
346 | ':' inner_statement_list T_ENDFOR ';' { $$ = $2; }
350 statement { $$ = toArray($1); }
351 | ':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; }
355 non_empty_statement { $$ = toArray($1); }
357 | ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; }
361 non_empty_declare_list no_comma { $$ = $1; }
364 non_empty_declare_list:
365 declare_list_element { init($1); }
366 | non_empty_declare_list ',' declare_list_element { push($1, $3); }
369 declare_list_element:
370 identifier '=' expr { $$ = Stmt\DeclareDeclare[$1, $3]; }
374 '{' case_list '}' { $$ = $2; }
375 | '{' ';' case_list '}' { $$ = $3; }
376 | ':' case_list T_ENDSWITCH ';' { $$ = $2; }
377 | ':' ';' case_list T_ENDSWITCH ';' { $$ = $3; }
381 /* empty */ { init(); }
382 | case_list case { push($1, $2); }
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]; }
396 statement { $$ = toArray($1); }
397 | ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; }
401 /* empty */ { init(); }
402 | elseif_list elseif { push($1, $2); }
406 T_ELSEIF '(' expr ')' statement { $$ = Stmt\ElseIf_[$3, toArray($5)]; }
410 /* empty */ { init(); }
411 | new_elseif_list new_elseif { push($1, $2); }
415 T_ELSEIF '(' expr ')' ':' inner_statement_list { $$ = Stmt\ElseIf_[$3, $6]; }
419 /* empty */ { $$ = null; }
420 | T_ELSE statement { $$ = Stmt\Else_[toArray($2)]; }
424 /* empty */ { $$ = null; }
425 | T_ELSE ':' inner_statement_list { $$ = Stmt\Else_[$3]; }
429 variable { $$ = array($1, false); }
430 | '&' variable { $$ = array($2, true); }
431 | list_expr { $$ = array($1, false); }
432 | array_short_syntax { $$ = array($1, false); }
436 non_empty_parameter_list no_comma { $$ = $1; }
437 | /* empty */ { $$ = array(); }
440 non_empty_parameter_list:
441 parameter { init($1); }
442 | non_empty_parameter_list ',' parameter { push($1, $3); }
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($$); }
454 | '?' type { $$ = Node\NullableType[$2]; }
458 name { $$ = $this->handleBuiltinTypes($1); }
459 | T_ARRAY { $$ = Node\Identifier['array']; }
460 | T_CALLABLE { $$ = Node\Identifier['callable']; }
464 /* empty */ { $$ = null; }
465 | type_expr { $$ = $1; }
468 optional_return_type:
469 /* empty */ { $$ = null; }
470 | ':' type_expr { $$ = $2; }
474 '(' ')' { $$ = array(); }
475 | '(' non_empty_argument_list optional_comma ')' { $$ = $2; }
478 non_empty_argument_list:
479 argument { init($1); }
480 | non_empty_argument_list ',' argument { push($1, $3); }
484 expr { $$ = Node\Arg[$1, false, false]; }
485 | '&' variable { $$ = Node\Arg[$2, true, false]; }
486 | T_ELLIPSIS expr { $$ = Node\Arg[$2, false, true]; }
490 non_empty_global_var_list no_comma { $$ = $1; }
493 non_empty_global_var_list:
494 non_empty_global_var_list ',' global_var { push($1, $3); }
495 | global_var { init($1); }
499 simple_variable { $$ = Expr\Variable[$1]; }
503 non_empty_static_var_list no_comma { $$ = $1; }
506 non_empty_static_var_list:
507 non_empty_static_var_list ',' static_var { push($1, $3); }
508 | static_var { init($1); }
512 plain_variable { $$ = Stmt\StaticVar[$1, null]; }
513 | plain_variable '=' expr { $$ = Stmt\StaticVar[$1, $3]; }
516 class_statement_list:
517 class_statement_list class_statement { push($1, $2); }
518 | /* empty */ { init(); }
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]; }
533 ';' { $$ = array(); }
534 | '{' trait_adaptation_list '}' { $$ = $2; }
537 trait_adaptation_list:
538 /* empty */ { init(); }
539 | trait_adaptation_list trait_adaptation { push($1, $2); }
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]; }
555 trait_method_reference_fully_qualified:
556 name T_PAAMAYIM_NEKUDOTAYIM identifier_ex { $$ = array($1, $3); }
558 trait_method_reference:
559 trait_method_reference_fully_qualified { $$ = $1; }
560 | identifier_ex { $$ = array(null, $1); }
564 ';' /* abstract method */ { $$ = null; }
565 | '{' inner_statement_list '}' { $$ = $2; }
569 non_empty_member_modifiers { $$ = $1; }
574 /* empty */ { $$ = 0; }
575 | non_empty_member_modifiers { $$ = $1; }
578 non_empty_member_modifiers:
579 member_modifier { $$ = $1; }
580 | non_empty_member_modifiers member_modifier { $this->checkModifier($1, $2, #2); $$ = $1 | $2; }
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; }
592 property_declaration_list:
593 non_empty_property_declaration_list no_comma { $$ = $1; }
596 non_empty_property_declaration_list:
597 property_declaration { init($1); }
598 | non_empty_property_declaration_list ',' property_declaration
603 T_VARIABLE { $$ = Node\VarLikeIdentifier[parseVar($1)]; }
606 property_declaration:
607 property_decl_name { $$ = Stmt\PropertyProperty[$1, null]; }
608 | property_decl_name '=' expr { $$ = Stmt\PropertyProperty[$1, $3]; }
612 non_empty_expr_list no_comma { $$ = $1; }
616 non_empty_expr_list ',' expr { push($1, $3); }
621 /* empty */ { $$ = array(); }
622 | expr_list { $$ = $1; }
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]; }
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]]; }
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); }
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]; }
731 /* empty */ { $$ = array(); }
732 | T_USE '(' lexical_var_list ')' { $$ = $3; }
736 non_empty_lexical_var_list no_comma { $$ = $1; }
739 non_empty_lexical_var_list:
740 lexical_var { init($1); }
741 | non_empty_lexical_var_list ',' lexical_var { push($1, $3); }
745 optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; }
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]; }
756 T_STATIC { $$ = Name[$1]; }
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]; }
766 class_name_reference:
767 class_name { $$ = $1; }
768 | new_variable { $$ = $1; }
769 | error { $$ = Expr\Error[]; $this->errorState = 2; }
773 class_name { $$ = $1; }
774 | dereferencable { $$ = $1; }
778 /* empty */ { $$ = null; }
779 | '(' optional_expr ')' { $$ = $2; }
783 /* empty */ { $$ = array(); }
784 | T_ENCAPSED_AND_WHITESPACE
785 { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`')]); }
786 | encaps_list { parseEncapsed($1, '`', true); $$ = $1; }
790 /* empty */ { $$ = array(); }
791 | argument_list { $$ = $1; }
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; }
805 '[' array_pair_list ']'
806 { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT;
807 $$ = new Expr\Array_($2, $attrs); }
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); }
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); }
848 /* empty */ { $$ = null; }
853 variable { $$ = $1; }
854 | '(' expr ')' { $$ = $2; }
855 | dereferencable_scalar { $$ = $1; }
859 callable_variable { $$ = $1; }
860 | '(' expr ')' { $$ = $2; }
861 | dereferencable_scalar { $$ = $1; }
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]; }
875 callable_variable { $$ = $1; }
876 | static_member { $$ = $1; }
877 | dereferencable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; }
881 T_VARIABLE { $$ = parseVar($1); }
882 | '$' '{' expr '}' { $$ = $3; }
883 | '$' simple_variable { $$ = Expr\Variable[$2]; }
884 | '$' error { $$ = Expr\Error[]; $this->errorState = 2; }
887 static_member_prop_name:
889 { $var = $1; $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; }
893 class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name
894 { $$ = Expr\StaticPropertyFetch[$1, $3]; }
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]; }
909 identifier_ex { $$ = $1; }
910 | '{' expr '}' { $$ = $2; }
911 | simple_variable { $$ = Expr\Variable[$1]; }
915 identifier { $$ = $1; }
916 | '{' expr '}' { $$ = $2; }
917 | simple_variable { $$ = Expr\Variable[$1]; }
918 | error { $$ = Expr\Error[]; $this->errorState = 2; }
922 T_LIST '(' list_expr_elements ')' { $$ = Expr\List_[$3]; }
926 list_expr_elements ',' list_expr_element { push($1, $3); }
927 | list_expr_element { init($1); }
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; }
941 inner_array_pair_list
942 { $$ = $1; $end = count($$)-1; if ($$[$end] === null) array_pop($$); }
945 inner_array_pair_list:
946 inner_array_pair_list ',' array_pair { push($1, $3); }
947 | array_pair { init($1); }
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; }
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); }
966 T_ENCAPSED_AND_WHITESPACE { $$ = Scalar\EncapsedStringPart[$1]; }
970 T_STRING_VARNAME { $$ = Expr\Variable[$1]; }
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; }
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; }