php5.y 49 KB

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