菜谱项目

php5.y 49KB

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