php5.y 49 KB

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