php7.y 44 KB

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