菜谱项目

php7.y 44KB

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