php5.y 49 KB

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