zend_language_parser.phpy 46 KB

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