You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1040 lines
50 KiB

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