xref: /PHP-7.4/Zend/zend_language_parser.y (revision 5265fabc)
1 %require "3.0"
2 %{
3 /*
4    +----------------------------------------------------------------------+
5    | Zend Engine                                                          |
6    +----------------------------------------------------------------------+
7    | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
8    +----------------------------------------------------------------------+
9    | This source file is subject to version 2.00 of the Zend license,     |
10    | that is bundled with this package in the file LICENSE, and is        |
11    | available through the world-wide-web at the following url:           |
12    | http://www.zend.com/license/2_00.txt.                                |
13    | If you did not receive a copy of the Zend license and are unable to  |
14    | obtain it through the world-wide-web, please send a note to          |
15    | license@zend.com so we can mail you a copy immediately.              |
16    +----------------------------------------------------------------------+
17    | Authors: Andi Gutmans <andi@php.net>                                 |
18    |          Zeev Suraski <zeev@php.net>                                 |
19    |          Nikita Popov <nikic@php.net>                                |
20    +----------------------------------------------------------------------+
21 */
22 
23 #include "zend_compile.h"
24 #include "zend.h"
25 #include "zend_list.h"
26 #include "zend_globals.h"
27 #include "zend_API.h"
28 #include "zend_constants.h"
29 #include "zend_language_scanner.h"
30 #include "zend_exceptions.h"
31 
32 #define YYSIZE_T size_t
33 #define yytnamerr zend_yytnamerr
34 static YYSIZE_T zend_yytnamerr(char*, const char*);
35 
36 #define YYSTYPE zend_parser_stack_elem
37 
38 #ifdef _MSC_VER
39 #define YYMALLOC malloc
40 #define YYFREE free
41 #endif
42 
43 %}
44 
45 %define api.pure full
46 %define parse.error verbose
47 %expect 0
48 
49 %code requires {
50 }
51 
52 %destructor { zend_ast_destroy($$); } <ast>
53 %destructor { if ($$) zend_string_release_ex($$, 0); } <str>
54 
55 %precedence PREC_ARROW_FUNCTION
56 %precedence T_INCLUDE T_INCLUDE_ONCE T_REQUIRE T_REQUIRE_ONCE
57 %left T_LOGICAL_OR
58 %left T_LOGICAL_XOR
59 %left T_LOGICAL_AND
60 %precedence T_PRINT
61 %precedence T_YIELD
62 %precedence T_DOUBLE_ARROW
63 %precedence T_YIELD_FROM
64 %precedence '=' 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 T_COALESCE_EQUAL
65 %left '?' ':'
66 %right T_COALESCE
67 %left T_BOOLEAN_OR
68 %left T_BOOLEAN_AND
69 %left '|'
70 %left '^'
71 %left '&'
72 %nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL T_SPACESHIP
73 %nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL
74 %left T_SL T_SR
75 %left '+' '-' '.'
76 %left '*' '/' '%'
77 %precedence '!'
78 %precedence T_INSTANCEOF
79 %precedence '~' T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@'
80 %right T_POW
81 %precedence T_NEW T_CLONE
82 
83 /* Resolve danging else conflict */
84 %precedence T_NOELSE
85 %precedence T_ELSEIF
86 %precedence T_ELSE
87 
88 %token <ast> T_LNUMBER   "integer number (T_LNUMBER)"
89 %token <ast> T_DNUMBER   "floating-point number (T_DNUMBER)"
90 %token <ast> T_STRING    "identifier (T_STRING)"
91 %token <ast> T_VARIABLE  "variable (T_VARIABLE)"
92 %token <ast> T_INLINE_HTML
93 %token <ast> T_ENCAPSED_AND_WHITESPACE  "quoted-string and whitespace (T_ENCAPSED_AND_WHITESPACE)"
94 %token <ast> T_CONSTANT_ENCAPSED_STRING "quoted-string (T_CONSTANT_ENCAPSED_STRING)"
95 %token <ast> T_STRING_VARNAME "variable name (T_STRING_VARNAME)"
96 %token <ast> T_NUM_STRING "number (T_NUM_STRING)"
97 
98 %token END 0 "end of file"
99 %token T_INCLUDE      "include (T_INCLUDE)"
100 %token T_INCLUDE_ONCE "include_once (T_INCLUDE_ONCE)"
101 %token T_EVAL         "eval (T_EVAL)"
102 %token T_REQUIRE      "require (T_REQUIRE)"
103 %token T_REQUIRE_ONCE "require_once (T_REQUIRE_ONCE)"
104 %token T_LOGICAL_OR   "or (T_LOGICAL_OR)"
105 %token T_LOGICAL_XOR  "xor (T_LOGICAL_XOR)"
106 %token T_LOGICAL_AND  "and (T_LOGICAL_AND)"
107 %token T_PRINT        "print (T_PRINT)"
108 %token T_YIELD        "yield (T_YIELD)"
109 %token T_YIELD_FROM   "yield from (T_YIELD_FROM)"
110 %token T_PLUS_EQUAL   "+= (T_PLUS_EQUAL)"
111 %token T_MINUS_EQUAL  "-= (T_MINUS_EQUAL)"
112 %token T_MUL_EQUAL    "*= (T_MUL_EQUAL)"
113 %token T_DIV_EQUAL    "/= (T_DIV_EQUAL)"
114 %token T_CONCAT_EQUAL ".= (T_CONCAT_EQUAL)"
115 %token T_MOD_EQUAL    "%= (T_MOD_EQUAL)"
116 %token T_AND_EQUAL    "&= (T_AND_EQUAL)"
117 %token T_OR_EQUAL     "|= (T_OR_EQUAL)"
118 %token T_XOR_EQUAL    "^= (T_XOR_EQUAL)"
119 %token T_SL_EQUAL     "<<= (T_SL_EQUAL)"
120 %token T_SR_EQUAL     ">>= (T_SR_EQUAL)"
121 %token T_COALESCE_EQUAL "??= (T_COALESCE_EQUAL)"
122 %token T_BOOLEAN_OR   "|| (T_BOOLEAN_OR)"
123 %token T_BOOLEAN_AND  "&& (T_BOOLEAN_AND)"
124 %token T_IS_EQUAL     "== (T_IS_EQUAL)"
125 %token T_IS_NOT_EQUAL "!= (T_IS_NOT_EQUAL)"
126 %token T_IS_IDENTICAL "=== (T_IS_IDENTICAL)"
127 %token T_IS_NOT_IDENTICAL "!== (T_IS_NOT_IDENTICAL)"
128 %token T_IS_SMALLER_OR_EQUAL "<= (T_IS_SMALLER_OR_EQUAL)"
129 %token T_IS_GREATER_OR_EQUAL ">= (T_IS_GREATER_OR_EQUAL)"
130 %token T_SPACESHIP "<=> (T_SPACESHIP)"
131 %token T_SL "<< (T_SL)"
132 %token T_SR ">> (T_SR)"
133 %token T_INSTANCEOF  "instanceof (T_INSTANCEOF)"
134 %token T_INC "++ (T_INC)"
135 %token T_DEC "-- (T_DEC)"
136 %token T_INT_CAST    "(int) (T_INT_CAST)"
137 %token T_DOUBLE_CAST "(double) (T_DOUBLE_CAST)"
138 %token T_STRING_CAST "(string) (T_STRING_CAST)"
139 %token T_ARRAY_CAST  "(array) (T_ARRAY_CAST)"
140 %token T_OBJECT_CAST "(object) (T_OBJECT_CAST)"
141 %token T_BOOL_CAST   "(bool) (T_BOOL_CAST)"
142 %token T_UNSET_CAST  "(unset) (T_UNSET_CAST)"
143 %token T_NEW       "new (T_NEW)"
144 %token T_CLONE     "clone (T_CLONE)"
145 %token T_EXIT      "exit (T_EXIT)"
146 %token T_IF        "if (T_IF)"
147 %token T_ELSEIF    "elseif (T_ELSEIF)"
148 %token T_ELSE      "else (T_ELSE)"
149 %token T_ENDIF     "endif (T_ENDIF)"
150 %token T_ECHO       "echo (T_ECHO)"
151 %token T_DO         "do (T_DO)"
152 %token T_WHILE      "while (T_WHILE)"
153 %token T_ENDWHILE   "endwhile (T_ENDWHILE)"
154 %token T_FOR        "for (T_FOR)"
155 %token T_ENDFOR     "endfor (T_ENDFOR)"
156 %token T_FOREACH    "foreach (T_FOREACH)"
157 %token T_ENDFOREACH "endforeach (T_ENDFOREACH)"
158 %token T_DECLARE    "declare (T_DECLARE)"
159 %token T_ENDDECLARE "enddeclare (T_ENDDECLARE)"
160 %token T_AS         "as (T_AS)"
161 %token T_SWITCH     "switch (T_SWITCH)"
162 %token T_ENDSWITCH  "endswitch (T_ENDSWITCH)"
163 %token T_CASE       "case (T_CASE)"
164 %token T_DEFAULT    "default (T_DEFAULT)"
165 %token T_BREAK      "break (T_BREAK)"
166 %token T_CONTINUE   "continue (T_CONTINUE)"
167 %token T_GOTO       "goto (T_GOTO)"
168 %token T_FUNCTION   "function (T_FUNCTION)"
169 %token T_FN         "fn (T_FN)"
170 %token T_CONST      "const (T_CONST)"
171 %token T_RETURN     "return (T_RETURN)"
172 %token T_TRY        "try (T_TRY)"
173 %token T_CATCH      "catch (T_CATCH)"
174 %token T_FINALLY    "finally (T_FINALLY)"
175 %token T_THROW      "throw (T_THROW)"
176 %token T_USE        "use (T_USE)"
177 %token T_INSTEADOF  "insteadof (T_INSTEADOF)"
178 %token T_GLOBAL     "global (T_GLOBAL)"
179 %token T_STATIC     "static (T_STATIC)"
180 %token T_ABSTRACT   "abstract (T_ABSTRACT)"
181 %token T_FINAL      "final (T_FINAL)"
182 %token T_PRIVATE    "private (T_PRIVATE)"
183 %token T_PROTECTED  "protected (T_PROTECTED)"
184 %token T_PUBLIC     "public (T_PUBLIC)"
185 %token T_VAR        "var (T_VAR)"
186 %token T_UNSET      "unset (T_UNSET)"
187 %token T_ISSET      "isset (T_ISSET)"
188 %token T_EMPTY      "empty (T_EMPTY)"
189 %token T_HALT_COMPILER "__halt_compiler (T_HALT_COMPILER)"
190 %token T_CLASS      "class (T_CLASS)"
191 %token T_TRAIT      "trait (T_TRAIT)"
192 %token T_INTERFACE  "interface (T_INTERFACE)"
193 %token T_EXTENDS    "extends (T_EXTENDS)"
194 %token T_IMPLEMENTS "implements (T_IMPLEMENTS)"
195 %token T_OBJECT_OPERATOR "-> (T_OBJECT_OPERATOR)"
196 %token T_DOUBLE_ARROW    "=> (T_DOUBLE_ARROW)"
197 %token T_LIST            "list (T_LIST)"
198 %token T_ARRAY           "array (T_ARRAY)"
199 %token T_CALLABLE        "callable (T_CALLABLE)"
200 %token T_LINE            "__LINE__ (T_LINE)"
201 %token T_FILE            "__FILE__ (T_FILE)"
202 %token T_DIR             "__DIR__ (T_DIR)"
203 %token T_CLASS_C         "__CLASS__ (T_CLASS_C)"
204 %token T_TRAIT_C         "__TRAIT__ (T_TRAIT_C)"
205 %token T_METHOD_C        "__METHOD__ (T_METHOD_C)"
206 %token T_FUNC_C          "__FUNCTION__ (T_FUNC_C)"
207 %token T_COMMENT         "comment (T_COMMENT)"
208 %token T_DOC_COMMENT     "doc comment (T_DOC_COMMENT)"
209 %token T_OPEN_TAG        "open tag (T_OPEN_TAG)"
210 %token T_OPEN_TAG_WITH_ECHO "open tag with echo (T_OPEN_TAG_WITH_ECHO)"
211 %token T_CLOSE_TAG       "close tag (T_CLOSE_TAG)"
212 %token T_WHITESPACE      "whitespace (T_WHITESPACE)"
213 %token T_START_HEREDOC   "heredoc start (T_START_HEREDOC)"
214 %token T_END_HEREDOC     "heredoc end (T_END_HEREDOC)"
215 %token T_DOLLAR_OPEN_CURLY_BRACES "${ (T_DOLLAR_OPEN_CURLY_BRACES)"
216 %token T_CURLY_OPEN      "{$ (T_CURLY_OPEN)"
217 %token T_PAAMAYIM_NEKUDOTAYIM ":: (T_PAAMAYIM_NEKUDOTAYIM)"
218 %token T_NAMESPACE       "namespace (T_NAMESPACE)"
219 %token T_NS_C            "__NAMESPACE__ (T_NS_C)"
220 %token T_NS_SEPARATOR    "\\ (T_NS_SEPARATOR)"
221 %token T_ELLIPSIS        "... (T_ELLIPSIS)"
222 %token T_COALESCE        "?? (T_COALESCE)"
223 %token T_POW             "** (T_POW)"
224 %token T_POW_EQUAL       "**= (T_POW_EQUAL)"
225 %token T_BAD_CHARACTER   "invalid character (T_BAD_CHARACTER)"
226 
227 /* Token used to force a parse error from the lexer */
228 %token T_ERROR
229 
230 %type <ast> top_statement namespace_name name statement function_declaration_statement
231 %type <ast> class_declaration_statement trait_declaration_statement
232 %type <ast> interface_declaration_statement interface_extends_list
233 %type <ast> group_use_declaration inline_use_declarations inline_use_declaration
234 %type <ast> mixed_group_use_declaration use_declaration unprefixed_use_declaration
235 %type <ast> unprefixed_use_declarations const_decl inner_statement
236 %type <ast> expr optional_expr while_statement for_statement foreach_variable
237 %type <ast> foreach_statement declare_statement finally_statement unset_variable variable
238 %type <ast> extends_from parameter optional_type argument global_var
239 %type <ast> static_var class_statement trait_adaptation trait_precedence trait_alias
240 %type <ast> absolute_trait_method_reference trait_method_reference property echo_expr
241 %type <ast> new_expr anonymous_class class_name class_name_reference simple_variable
242 %type <ast> internal_functions_in_yacc
243 %type <ast> exit_expr scalar backticks_expr lexical_var function_call member_name property_name
244 %type <ast> variable_class_name dereferencable_scalar constant dereferencable
245 %type <ast> callable_expr callable_variable static_member new_variable
246 %type <ast> encaps_var encaps_var_offset isset_variables
247 %type <ast> top_statement_list use_declarations const_list inner_statement_list if_stmt
248 %type <ast> alt_if_stmt for_exprs switch_case_list global_var_list static_var_list
249 %type <ast> echo_expr_list unset_variables catch_name_list catch_list parameter_list class_statement_list
250 %type <ast> implements_list case_list if_stmt_without_else
251 %type <ast> non_empty_parameter_list argument_list non_empty_argument_list property_list
252 %type <ast> class_const_list class_const_decl name_list trait_adaptations method_body non_empty_for_exprs
253 %type <ast> ctor_arguments alt_if_stmt_without_else trait_adaptation_list lexical_vars
254 %type <ast> lexical_var_list encaps_list
255 %type <ast> array_pair non_empty_array_pair_list array_pair_list possible_array_pair
256 %type <ast> isset_variable type return_type type_expr
257 %type <ast> identifier
258 %type <ast> inline_function
259 
260 %type <num> returns_ref function fn is_reference is_variadic variable_modifiers
261 %type <num> method_modifiers non_empty_member_modifiers member_modifier
262 %type <num> class_modifiers class_modifier use_type backup_fn_flags
263 
264 %type <ptr> backup_lex_pos
265 %type <str> backup_doc_comment
266 
267 %% /* Rules */
268 
269 start:
270 	top_statement_list	{ CG(ast) = $1; }
271 ;
272 
273 reserved_non_modifiers:
274 	  T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND
275 	| T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE | T_ENDWHILE
276 	| T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH | T_FINALLY
277 	| T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
278 	| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT | T_BREAK
279 	| T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
280 	| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_FN
281 ;
282 
283 semi_reserved:
284 	  reserved_non_modifiers
285 	| T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
286 ;
287 
288 identifier:
289 		T_STRING { $$ = $1; }
290 	| 	semi_reserved  {
291 			zval zv;
292 			zend_lex_tstring(&zv);
293 			$$ = zend_ast_create_zval(&zv);
294 		}
295 ;
296 
297 top_statement_list:
298 		top_statement_list top_statement { $$ = zend_ast_list_add($1, $2); }
299 	|	/* empty */ { $$ = zend_ast_create_list(0, ZEND_AST_STMT_LIST); }
300 ;
301 
302 namespace_name:
303 		T_STRING								{ $$ = $1; }
304 	|	namespace_name T_NS_SEPARATOR T_STRING	{ $$ = zend_ast_append_str($1, $3); }
305 ;
306 
307 name:
308 		namespace_name								{ $$ = $1; $$->attr = ZEND_NAME_NOT_FQ; }
309 	|	T_NAMESPACE T_NS_SEPARATOR namespace_name	{ $$ = $3; $$->attr = ZEND_NAME_RELATIVE; }
310 	|	T_NS_SEPARATOR namespace_name				{ $$ = $2; $$->attr = ZEND_NAME_FQ; }
311 ;
312 
313 top_statement:
314 		statement							{ $$ = $1; }
315 	|	function_declaration_statement		{ $$ = $1; }
316 	|	class_declaration_statement			{ $$ = $1; }
317 	|	trait_declaration_statement			{ $$ = $1; }
318 	|	interface_declaration_statement		{ $$ = $1; }
319 	|	T_HALT_COMPILER '(' ')' ';'
320 			{ $$ = zend_ast_create(ZEND_AST_HALT_COMPILER,
321 			      zend_ast_create_zval_from_long(zend_get_scanned_file_offset()));
322 			  zend_stop_lexing(); }
323 	|	T_NAMESPACE namespace_name ';'
324 			{ $$ = zend_ast_create(ZEND_AST_NAMESPACE, $2, NULL);
325 			  RESET_DOC_COMMENT(); }
326 	|	T_NAMESPACE namespace_name { RESET_DOC_COMMENT(); }
327 		'{' top_statement_list '}'
328 			{ $$ = zend_ast_create(ZEND_AST_NAMESPACE, $2, $5); }
329 	|	T_NAMESPACE { RESET_DOC_COMMENT(); }
330 		'{' top_statement_list '}'
331 			{ $$ = zend_ast_create(ZEND_AST_NAMESPACE, NULL, $4); }
332 	|	T_USE mixed_group_use_declaration ';'		{ $$ = $2; }
333 	|	T_USE use_type group_use_declaration ';'	{ $$ = $3; $$->attr = $2; }
334 	|	T_USE use_declarations ';'					{ $$ = $2; $$->attr = ZEND_SYMBOL_CLASS; }
335 	|	T_USE use_type use_declarations ';'			{ $$ = $3; $$->attr = $2; }
336 	|	T_CONST const_list ';'						{ $$ = $2; }
337 ;
338 
339 use_type:
340 	 	T_FUNCTION 		{ $$ = ZEND_SYMBOL_FUNCTION; }
341 	| 	T_CONST 		{ $$ = ZEND_SYMBOL_CONST; }
342 ;
343 
344 group_use_declaration:
345 		namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
346 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4); }
347 	|	T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
348 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $2, $5); }
349 ;
350 
351 mixed_group_use_declaration:
352 		namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
353 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4);}
354 	|	T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
355 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $2, $5); }
356 ;
357 
358 possible_comma:
359 		/* empty */
360 	|	','
361 ;
362 
363 inline_use_declarations:
364 		inline_use_declarations ',' inline_use_declaration
365 			{ $$ = zend_ast_list_add($1, $3); }
366 	|	inline_use_declaration
367 			{ $$ = zend_ast_create_list(1, ZEND_AST_USE, $1); }
368 ;
369 
370 unprefixed_use_declarations:
371 		unprefixed_use_declarations ',' unprefixed_use_declaration
372 			{ $$ = zend_ast_list_add($1, $3); }
373 	|	unprefixed_use_declaration
374 			{ $$ = zend_ast_create_list(1, ZEND_AST_USE, $1); }
375 ;
376 
377 use_declarations:
378 		use_declarations ',' use_declaration
379 			{ $$ = zend_ast_list_add($1, $3); }
380 	|	use_declaration
381 			{ $$ = zend_ast_create_list(1, ZEND_AST_USE, $1); }
382 ;
383 
384 inline_use_declaration:
385 		unprefixed_use_declaration { $$ = $1; $$->attr = ZEND_SYMBOL_CLASS; }
386 	|	use_type unprefixed_use_declaration { $$ = $2; $$->attr = $1; }
387 ;
388 
389 unprefixed_use_declaration:
390 		namespace_name
391 			{ $$ = zend_ast_create(ZEND_AST_USE_ELEM, $1, NULL); }
392 	|	namespace_name T_AS T_STRING
393 			{ $$ = zend_ast_create(ZEND_AST_USE_ELEM, $1, $3); }
394 ;
395 
396 use_declaration:
397 		unprefixed_use_declaration                { $$ = $1; }
398 	|	T_NS_SEPARATOR unprefixed_use_declaration { $$ = $2; }
399 ;
400 
401 const_list:
402 		const_list ',' const_decl { $$ = zend_ast_list_add($1, $3); }
403 	|	const_decl { $$ = zend_ast_create_list(1, ZEND_AST_CONST_DECL, $1); }
404 ;
405 
406 inner_statement_list:
407 		inner_statement_list inner_statement
408 			{ $$ = zend_ast_list_add($1, $2); }
409 	|	/* empty */
410 			{ $$ = zend_ast_create_list(0, ZEND_AST_STMT_LIST); }
411 ;
412 
413 
414 inner_statement:
415 		statement { $$ = $1; }
416 	|	function_declaration_statement 		{ $$ = $1; }
417 	|	class_declaration_statement 		{ $$ = $1; }
418 	|	trait_declaration_statement			{ $$ = $1; }
419 	|	interface_declaration_statement		{ $$ = $1; }
420 	|	T_HALT_COMPILER '(' ')' ';'
421 			{ $$ = NULL; zend_throw_exception(zend_ce_compile_error,
422 			      "__HALT_COMPILER() can only be used from the outermost scope", 0); YYERROR; }
423 ;
424 
425 
426 statement:
427 		'{' inner_statement_list '}' { $$ = $2; }
428 	|	if_stmt { $$ = $1; }
429 	|	alt_if_stmt { $$ = $1; }
430 	|	T_WHILE '(' expr ')' while_statement
431 			{ $$ = zend_ast_create(ZEND_AST_WHILE, $3, $5); }
432 	|	T_DO statement T_WHILE '(' expr ')' ';'
433 			{ $$ = zend_ast_create(ZEND_AST_DO_WHILE, $2, $5); }
434 	|	T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement
435 			{ $$ = zend_ast_create(ZEND_AST_FOR, $3, $5, $7, $9); }
436 	|	T_SWITCH '(' expr ')' switch_case_list
437 			{ $$ = zend_ast_create(ZEND_AST_SWITCH, $3, $5); }
438 	|	T_BREAK optional_expr ';'		{ $$ = zend_ast_create(ZEND_AST_BREAK, $2); }
439 	|	T_CONTINUE optional_expr ';'	{ $$ = zend_ast_create(ZEND_AST_CONTINUE, $2); }
440 	|	T_RETURN optional_expr ';'		{ $$ = zend_ast_create(ZEND_AST_RETURN, $2); }
441 	|	T_GLOBAL global_var_list ';'	{ $$ = $2; }
442 	|	T_STATIC static_var_list ';'	{ $$ = $2; }
443 	|	T_ECHO echo_expr_list ';'		{ $$ = $2; }
444 	|	T_INLINE_HTML { $$ = zend_ast_create(ZEND_AST_ECHO, $1); }
445 	|	expr ';' { $$ = $1; }
446 	|	T_UNSET '(' unset_variables possible_comma ')' ';' { $$ = $3; }
447 	|	T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
448 			{ $$ = zend_ast_create(ZEND_AST_FOREACH, $3, $5, NULL, $7); }
449 	|	T_FOREACH '(' expr T_AS foreach_variable T_DOUBLE_ARROW foreach_variable ')'
450 		foreach_statement
451 			{ $$ = zend_ast_create(ZEND_AST_FOREACH, $3, $7, $5, $9); }
452 	|	T_DECLARE '(' const_list ')'
453 			{ if (!zend_handle_encoding_declaration($3)) { YYERROR; } }
454 		declare_statement
455 			{ $$ = zend_ast_create(ZEND_AST_DECLARE, $3, $6); }
456 	|	';'	/* empty statement */ { $$ = NULL; }
457 	|	T_TRY '{' inner_statement_list '}' catch_list finally_statement
458 			{ $$ = zend_ast_create(ZEND_AST_TRY, $3, $5, $6); }
459 	|	T_THROW expr ';' { $$ = zend_ast_create(ZEND_AST_THROW, $2); }
460 	|	T_GOTO T_STRING ';' { $$ = zend_ast_create(ZEND_AST_GOTO, $2); }
461 	|	T_STRING ':' { $$ = zend_ast_create(ZEND_AST_LABEL, $1); }
462 ;
463 
464 catch_list:
465 		/* empty */
466 			{ $$ = zend_ast_create_list(0, ZEND_AST_CATCH_LIST); }
467 	|	catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}'
468 			{ $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_CATCH, $4, $5, $8)); }
469 ;
470 
471 catch_name_list:
472 		name { $$ = zend_ast_create_list(1, ZEND_AST_NAME_LIST, $1); }
473 	|	catch_name_list '|' name { $$ = zend_ast_list_add($1, $3); }
474 ;
475 
476 finally_statement:
477 		/* empty */ { $$ = NULL; }
478 	|	T_FINALLY '{' inner_statement_list '}' { $$ = $3; }
479 ;
480 
481 unset_variables:
482 		unset_variable { $$ = zend_ast_create_list(1, ZEND_AST_STMT_LIST, $1); }
483 	|	unset_variables ',' unset_variable { $$ = zend_ast_list_add($1, $3); }
484 ;
485 
486 unset_variable:
487 		variable { $$ = zend_ast_create(ZEND_AST_UNSET, $1); }
488 ;
489 
490 function_declaration_statement:
491 	function returns_ref T_STRING backup_doc_comment '(' parameter_list ')' return_type
492 	backup_fn_flags '{' inner_statement_list '}' backup_fn_flags
493 		{ $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2 | $13, $1, $4,
494 		      zend_ast_get_str($3), $6, NULL, $11, $8); CG(extra_fn_flags) = $9; }
495 ;
496 
497 is_reference:
498 		/* empty */	{ $$ = 0; }
499 	|	'&'			{ $$ = ZEND_PARAM_REF; }
500 ;
501 
502 is_variadic:
503 		/* empty */ { $$ = 0; }
504 	|	T_ELLIPSIS  { $$ = ZEND_PARAM_VARIADIC; }
505 ;
506 
507 class_declaration_statement:
508 		class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
509 		T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
510 			{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL); }
511 	|	T_CLASS { $<num>$ = CG(zend_lineno); }
512 		T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
513 			{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL); }
514 ;
515 
516 class_modifiers:
517 		class_modifier 					{ $$ = $1; }
518 	|	class_modifiers class_modifier
519 			{ $$ = zend_add_class_modifier($1, $2); if (!$$) { YYERROR; } }
520 ;
521 
522 class_modifier:
523 		T_ABSTRACT 		{ $$ = ZEND_ACC_EXPLICIT_ABSTRACT_CLASS; }
524 	|	T_FINAL 		{ $$ = ZEND_ACC_FINAL; }
525 ;
526 
527 trait_declaration_statement:
528 		T_TRAIT { $<num>$ = CG(zend_lineno); }
529 		T_STRING backup_doc_comment '{' class_statement_list '}'
530 			{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6, NULL); }
531 ;
532 
533 interface_declaration_statement:
534 		T_INTERFACE { $<num>$ = CG(zend_lineno); }
535 		T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
536 			{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2, $5, zend_ast_get_str($3), NULL, $4, $7, NULL); }
537 ;
538 
539 extends_from:
540 		/* empty */		{ $$ = NULL; }
541 	|	T_EXTENDS name	{ $$ = $2; }
542 ;
543 
544 interface_extends_list:
545 		/* empty */			{ $$ = NULL; }
546 	|	T_EXTENDS name_list	{ $$ = $2; }
547 ;
548 
549 implements_list:
550 		/* empty */				{ $$ = NULL; }
551 	|	T_IMPLEMENTS name_list	{ $$ = $2; }
552 ;
553 
554 foreach_variable:
555 		variable			{ $$ = $1; }
556 	|	'&' variable		{ $$ = zend_ast_create(ZEND_AST_REF, $2); }
557 	|	T_LIST '(' array_pair_list ')' { $$ = $3; $$->attr = ZEND_ARRAY_SYNTAX_LIST; }
558 	|	'[' array_pair_list ']' { $$ = $2; $$->attr = ZEND_ARRAY_SYNTAX_SHORT; }
559 ;
560 
561 for_statement:
562 		statement { $$ = $1; }
563 	|	':' inner_statement_list T_ENDFOR ';' { $$ = $2; }
564 ;
565 
566 foreach_statement:
567 		statement { $$ = $1; }
568 	|	':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; }
569 ;
570 
571 declare_statement:
572 		statement { $$ = $1; }
573 	|	':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; }
574 ;
575 
576 switch_case_list:
577 		'{' case_list '}'					{ $$ = $2; }
578 	|	'{' ';' case_list '}'				{ $$ = $3; }
579 	|	':' case_list T_ENDSWITCH ';'		{ $$ = $2; }
580 	|	':' ';' case_list T_ENDSWITCH ';'	{ $$ = $3; }
581 ;
582 
583 case_list:
584 		/* empty */ { $$ = zend_ast_create_list(0, ZEND_AST_SWITCH_LIST); }
585 	|	case_list T_CASE expr case_separator inner_statement_list
586 			{ $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_SWITCH_CASE, $3, $5)); }
587 	|	case_list T_DEFAULT case_separator inner_statement_list
588 			{ $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_SWITCH_CASE, NULL, $4)); }
589 ;
590 
591 case_separator:
592 		':'
593 	|	';'
594 ;
595 
596 
597 while_statement:
598 		statement { $$ = $1; }
599 	|	':' inner_statement_list T_ENDWHILE ';' { $$ = $2; }
600 ;
601 
602 
603 if_stmt_without_else:
604 		T_IF '(' expr ')' statement
605 			{ $$ = zend_ast_create_list(1, ZEND_AST_IF,
606 			      zend_ast_create(ZEND_AST_IF_ELEM, $3, $5)); }
607 	|	if_stmt_without_else T_ELSEIF '(' expr ')' statement
608 			{ $$ = zend_ast_list_add($1,
609 			      zend_ast_create(ZEND_AST_IF_ELEM, $4, $6)); }
610 ;
611 
612 if_stmt:
613 		if_stmt_without_else %prec T_NOELSE { $$ = $1; }
614 	|	if_stmt_without_else T_ELSE statement
615 			{ $$ = zend_ast_list_add($1, zend_ast_create(ZEND_AST_IF_ELEM, NULL, $3)); }
616 ;
617 
618 alt_if_stmt_without_else:
619 		T_IF '(' expr ')' ':' inner_statement_list
620 			{ $$ = zend_ast_create_list(1, ZEND_AST_IF,
621 			      zend_ast_create(ZEND_AST_IF_ELEM, $3, $6)); }
622 	|	alt_if_stmt_without_else T_ELSEIF '(' expr ')' ':' inner_statement_list
623 			{ $$ = zend_ast_list_add($1,
624 			      zend_ast_create(ZEND_AST_IF_ELEM, $4, $7)); }
625 ;
626 
627 alt_if_stmt:
628 		alt_if_stmt_without_else T_ENDIF ';' { $$ = $1; }
629 	|	alt_if_stmt_without_else T_ELSE ':' inner_statement_list T_ENDIF ';'
630 			{ $$ = zend_ast_list_add($1,
631 			      zend_ast_create(ZEND_AST_IF_ELEM, NULL, $4)); }
632 ;
633 
634 parameter_list:
635 		non_empty_parameter_list { $$ = $1; }
636 	|	/* empty */	{ $$ = zend_ast_create_list(0, ZEND_AST_PARAM_LIST); }
637 ;
638 
639 
640 non_empty_parameter_list:
641 		parameter
642 			{ $$ = zend_ast_create_list(1, ZEND_AST_PARAM_LIST, $1); }
643 	|	non_empty_parameter_list ',' parameter
644 			{ $$ = zend_ast_list_add($1, $3); }
645 ;
646 
647 parameter:
648 		optional_type is_reference is_variadic T_VARIABLE
649 			{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $2 | $3, $1, $4, NULL); }
650 	|	optional_type is_reference is_variadic T_VARIABLE '=' expr
651 			{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $2 | $3, $1, $4, $6); }
652 ;
653 
654 
655 optional_type:
656 		/* empty */	{ $$ = NULL; }
657 	|	type_expr	{ $$ = $1; }
658 ;
659 
660 type_expr:
661 		type		{ $$ = $1; }
662 	|	'?' type	{ $$ = $2; $$->attr |= ZEND_TYPE_NULLABLE; }
663 ;
664 
665 type:
666 		T_ARRAY		{ $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); }
667 	|	T_CALLABLE	{ $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); }
668 	|	name		{ $$ = $1; }
669 ;
670 
671 return_type:
672 		/* empty */	{ $$ = NULL; }
673 	|	':' type_expr	{ $$ = $2; }
674 ;
675 
676 argument_list:
677 		'(' ')'	{ $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); }
678 	|	'(' non_empty_argument_list possible_comma ')' { $$ = $2; }
679 ;
680 
681 non_empty_argument_list:
682 		argument
683 			{ $$ = zend_ast_create_list(1, ZEND_AST_ARG_LIST, $1); }
684 	|	non_empty_argument_list ',' argument
685 			{ $$ = zend_ast_list_add($1, $3); }
686 ;
687 
688 argument:
689 		expr			{ $$ = $1; }
690 	|	T_ELLIPSIS expr	{ $$ = zend_ast_create(ZEND_AST_UNPACK, $2); }
691 ;
692 
693 global_var_list:
694 		global_var_list ',' global_var { $$ = zend_ast_list_add($1, $3); }
695 	|	global_var { $$ = zend_ast_create_list(1, ZEND_AST_STMT_LIST, $1); }
696 ;
697 
698 global_var:
699 	simple_variable
700 		{ $$ = zend_ast_create(ZEND_AST_GLOBAL, zend_ast_create(ZEND_AST_VAR, $1)); }
701 ;
702 
703 
704 static_var_list:
705 		static_var_list ',' static_var { $$ = zend_ast_list_add($1, $3); }
706 	|	static_var { $$ = zend_ast_create_list(1, ZEND_AST_STMT_LIST, $1); }
707 ;
708 
709 static_var:
710 		T_VARIABLE			{ $$ = zend_ast_create(ZEND_AST_STATIC, $1, NULL); }
711 	|	T_VARIABLE '=' expr	{ $$ = zend_ast_create(ZEND_AST_STATIC, $1, $3); }
712 ;
713 
714 
715 class_statement_list:
716 		class_statement_list class_statement
717 			{ $$ = zend_ast_list_add($1, $2); }
718 	|	/* empty */
719 			{ $$ = zend_ast_create_list(0, ZEND_AST_STMT_LIST); }
720 ;
721 
722 
723 class_statement:
724 		variable_modifiers optional_type property_list ';'
725 			{ $$ = zend_ast_create(ZEND_AST_PROP_GROUP, $2, $3);
726 			  $$->attr = $1; }
727 	|	method_modifiers T_CONST class_const_list ';'
728 			{ $$ = $3; $$->attr = $1; }
729 	|	T_USE name_list trait_adaptations
730 			{ $$ = zend_ast_create(ZEND_AST_USE_TRAIT, $2, $3); }
731 	|	method_modifiers function returns_ref identifier backup_doc_comment '(' parameter_list ')'
732 		return_type backup_fn_flags method_body backup_fn_flags
733 			{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,
734 				  zend_ast_get_str($4), $7, NULL, $11, $9); CG(extra_fn_flags) = $10; }
735 ;
736 
737 name_list:
738 		name { $$ = zend_ast_create_list(1, ZEND_AST_NAME_LIST, $1); }
739 	|	name_list ',' name { $$ = zend_ast_list_add($1, $3); }
740 ;
741 
742 trait_adaptations:
743 		';'								{ $$ = NULL; }
744 	|	'{' '}'							{ $$ = NULL; }
745 	|	'{' trait_adaptation_list '}'	{ $$ = $2; }
746 ;
747 
748 trait_adaptation_list:
749 		trait_adaptation
750 			{ $$ = zend_ast_create_list(1, ZEND_AST_TRAIT_ADAPTATIONS, $1); }
751 	|	trait_adaptation_list trait_adaptation
752 			{ $$ = zend_ast_list_add($1, $2); }
753 ;
754 
755 trait_adaptation:
756 		trait_precedence ';'	{ $$ = $1; }
757 	|	trait_alias ';'			{ $$ = $1; }
758 ;
759 
760 trait_precedence:
761 	absolute_trait_method_reference T_INSTEADOF name_list
762 		{ $$ = zend_ast_create(ZEND_AST_TRAIT_PRECEDENCE, $1, $3); }
763 ;
764 
765 trait_alias:
766 		trait_method_reference T_AS T_STRING
767 			{ $$ = zend_ast_create(ZEND_AST_TRAIT_ALIAS, $1, $3); }
768 	|	trait_method_reference T_AS reserved_non_modifiers
769 			{ zval zv; zend_lex_tstring(&zv); $$ = zend_ast_create(ZEND_AST_TRAIT_ALIAS, $1, zend_ast_create_zval(&zv)); }
770 	|	trait_method_reference T_AS member_modifier identifier
771 			{ $$ = zend_ast_create_ex(ZEND_AST_TRAIT_ALIAS, $3, $1, $4); }
772 	|	trait_method_reference T_AS member_modifier
773 			{ $$ = zend_ast_create_ex(ZEND_AST_TRAIT_ALIAS, $3, $1, NULL); }
774 ;
775 
776 trait_method_reference:
777 		identifier
778 			{ $$ = zend_ast_create(ZEND_AST_METHOD_REFERENCE, NULL, $1); }
779 	|	absolute_trait_method_reference { $$ = $1; }
780 ;
781 
782 absolute_trait_method_reference:
783 	name T_PAAMAYIM_NEKUDOTAYIM identifier
784 		{ $$ = zend_ast_create(ZEND_AST_METHOD_REFERENCE, $1, $3); }
785 ;
786 
787 method_body:
788 		';' /* abstract method */		{ $$ = NULL; }
789 	|	'{' inner_statement_list '}'	{ $$ = $2; }
790 ;
791 
792 variable_modifiers:
793 		non_empty_member_modifiers		{ $$ = $1; }
794 	|	T_VAR							{ $$ = ZEND_ACC_PUBLIC; }
795 ;
796 
797 method_modifiers:
798 		/* empty */						{ $$ = ZEND_ACC_PUBLIC; }
799 	|	non_empty_member_modifiers
800 			{ $$ = $1; if (!($$ & ZEND_ACC_PPP_MASK)) { $$ |= ZEND_ACC_PUBLIC; } }
801 ;
802 
803 non_empty_member_modifiers:
804 		member_modifier			{ $$ = $1; }
805 	|	non_empty_member_modifiers member_modifier
806 			{ $$ = zend_add_member_modifier($1, $2); if (!$$) { YYERROR; } }
807 ;
808 
809 member_modifier:
810 		T_PUBLIC				{ $$ = ZEND_ACC_PUBLIC; }
811 	|	T_PROTECTED				{ $$ = ZEND_ACC_PROTECTED; }
812 	|	T_PRIVATE				{ $$ = ZEND_ACC_PRIVATE; }
813 	|	T_STATIC				{ $$ = ZEND_ACC_STATIC; }
814 	|	T_ABSTRACT				{ $$ = ZEND_ACC_ABSTRACT; }
815 	|	T_FINAL					{ $$ = ZEND_ACC_FINAL; }
816 ;
817 
818 property_list:
819 		property_list ',' property { $$ = zend_ast_list_add($1, $3); }
820 	|	property { $$ = zend_ast_create_list(1, ZEND_AST_PROP_DECL, $1); }
821 ;
822 
823 property:
824 		T_VARIABLE backup_doc_comment
825 			{ $$ = zend_ast_create(ZEND_AST_PROP_ELEM, $1, NULL, ($2 ? zend_ast_create_zval_from_str($2) : NULL)); }
826 	|	T_VARIABLE '=' expr backup_doc_comment
827 			{ $$ = zend_ast_create(ZEND_AST_PROP_ELEM, $1, $3, ($4 ? zend_ast_create_zval_from_str($4) : NULL)); }
828 ;
829 
830 class_const_list:
831 		class_const_list ',' class_const_decl { $$ = zend_ast_list_add($1, $3); }
832 	|	class_const_decl { $$ = zend_ast_create_list(1, ZEND_AST_CLASS_CONST_DECL, $1); }
833 ;
834 
835 class_const_decl:
836 	identifier '=' expr backup_doc_comment { $$ = zend_ast_create(ZEND_AST_CONST_ELEM, $1, $3, ($4 ? zend_ast_create_zval_from_str($4) : NULL)); }
837 ;
838 
839 const_decl:
840 	T_STRING '=' expr backup_doc_comment { $$ = zend_ast_create(ZEND_AST_CONST_ELEM, $1, $3, ($4 ? zend_ast_create_zval_from_str($4) : NULL)); }
841 ;
842 
843 echo_expr_list:
844 		echo_expr_list ',' echo_expr { $$ = zend_ast_list_add($1, $3); }
845 	|	echo_expr { $$ = zend_ast_create_list(1, ZEND_AST_STMT_LIST, $1); }
846 ;
847 echo_expr:
848 	expr { $$ = zend_ast_create(ZEND_AST_ECHO, $1); }
849 ;
850 
851 for_exprs:
852 		/* empty */			{ $$ = NULL; }
853 	|	non_empty_for_exprs	{ $$ = $1; }
854 ;
855 
856 non_empty_for_exprs:
857 		non_empty_for_exprs ',' expr { $$ = zend_ast_list_add($1, $3); }
858 	|	expr { $$ = zend_ast_create_list(1, ZEND_AST_EXPR_LIST, $1); }
859 ;
860 
861 anonymous_class:
862         T_CLASS { $<num>$ = CG(zend_lineno); } ctor_arguments
863 		extends_from implements_list backup_doc_comment '{' class_statement_list '}' {
864 			zend_ast *decl = zend_ast_create_decl(
865 				ZEND_AST_CLASS, ZEND_ACC_ANON_CLASS, $<num>2, $6, NULL,
866 				$4, $5, $8, NULL);
867 			$$ = zend_ast_create(ZEND_AST_NEW, decl, $3);
868 		}
869 ;
870 
871 new_expr:
872 		T_NEW class_name_reference ctor_arguments
873 			{ $$ = zend_ast_create(ZEND_AST_NEW, $2, $3); }
874 	|	T_NEW anonymous_class
875 			{ $$ = $2; }
876 ;
877 
878 expr:
879 		variable
880 			{ $$ = $1; }
881 	|	T_LIST '(' array_pair_list ')' '=' expr
882 			{ $3->attr = ZEND_ARRAY_SYNTAX_LIST; $$ = zend_ast_create(ZEND_AST_ASSIGN, $3, $6); }
883 	|	'[' array_pair_list ']' '=' expr
884 			{ $2->attr = ZEND_ARRAY_SYNTAX_SHORT; $$ = zend_ast_create(ZEND_AST_ASSIGN, $2, $5); }
885 	|	variable '=' expr
886 			{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
887 	|	variable '=' '&' variable
888 			{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
889 	|	T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2); }
890 	|	variable T_PLUS_EQUAL expr
891 			{ $$ = zend_ast_create_assign_op(ZEND_ADD, $1, $3); }
892 	|	variable T_MINUS_EQUAL expr
893 			{ $$ = zend_ast_create_assign_op(ZEND_SUB, $1, $3); }
894 	|	variable T_MUL_EQUAL expr
895 			{ $$ = zend_ast_create_assign_op(ZEND_MUL, $1, $3); }
896 	|	variable T_POW_EQUAL expr
897 			{ $$ = zend_ast_create_assign_op(ZEND_POW, $1, $3); }
898 	|	variable T_DIV_EQUAL expr
899 			{ $$ = zend_ast_create_assign_op(ZEND_DIV, $1, $3); }
900 	|	variable T_CONCAT_EQUAL expr
901 			{ $$ = zend_ast_create_assign_op(ZEND_CONCAT, $1, $3); }
902 	|	variable T_MOD_EQUAL expr
903 			{ $$ = zend_ast_create_assign_op(ZEND_MOD, $1, $3); }
904 	|	variable T_AND_EQUAL expr
905 			{ $$ = zend_ast_create_assign_op(ZEND_BW_AND, $1, $3); }
906 	|	variable T_OR_EQUAL expr
907 			{ $$ = zend_ast_create_assign_op(ZEND_BW_OR, $1, $3); }
908 	|	variable T_XOR_EQUAL expr
909 			{ $$ = zend_ast_create_assign_op(ZEND_BW_XOR, $1, $3); }
910 	|	variable T_SL_EQUAL expr
911 			{ $$ = zend_ast_create_assign_op(ZEND_SL, $1, $3); }
912 	|	variable T_SR_EQUAL expr
913 			{ $$ = zend_ast_create_assign_op(ZEND_SR, $1, $3); }
914 	|	variable T_COALESCE_EQUAL expr
915 			{ $$ = zend_ast_create(ZEND_AST_ASSIGN_COALESCE, $1, $3); }
916 	|	variable T_INC { $$ = zend_ast_create(ZEND_AST_POST_INC, $1); }
917 	|	T_INC variable { $$ = zend_ast_create(ZEND_AST_PRE_INC, $2); }
918 	|	variable T_DEC { $$ = zend_ast_create(ZEND_AST_POST_DEC, $1); }
919 	|	T_DEC variable { $$ = zend_ast_create(ZEND_AST_PRE_DEC, $2); }
920 	|	expr T_BOOLEAN_OR expr
921 			{ $$ = zend_ast_create(ZEND_AST_OR, $1, $3); }
922 	|	expr T_BOOLEAN_AND expr
923 			{ $$ = zend_ast_create(ZEND_AST_AND, $1, $3); }
924 	|	expr T_LOGICAL_OR expr
925 			{ $$ = zend_ast_create(ZEND_AST_OR, $1, $3); }
926 	|	expr T_LOGICAL_AND expr
927 			{ $$ = zend_ast_create(ZEND_AST_AND, $1, $3); }
928 	|	expr T_LOGICAL_XOR expr
929 			{ $$ = zend_ast_create_binary_op(ZEND_BOOL_XOR, $1, $3); }
930 	|	expr '|' expr	{ $$ = zend_ast_create_binary_op(ZEND_BW_OR, $1, $3); }
931 	|	expr '&' expr	{ $$ = zend_ast_create_binary_op(ZEND_BW_AND, $1, $3); }
932 	|	expr '^' expr	{ $$ = zend_ast_create_binary_op(ZEND_BW_XOR, $1, $3); }
933 	|	expr '.' expr 	{ $$ = zend_ast_create_binary_op(ZEND_CONCAT, $1, $3); }
934 	|	expr '+' expr 	{ $$ = zend_ast_create_binary_op(ZEND_ADD, $1, $3); }
935 	|	expr '-' expr 	{ $$ = zend_ast_create_binary_op(ZEND_SUB, $1, $3); }
936 	|	expr '*' expr	{ $$ = zend_ast_create_binary_op(ZEND_MUL, $1, $3); }
937 	|	expr T_POW expr	{ $$ = zend_ast_create_binary_op(ZEND_POW, $1, $3); }
938 	|	expr '/' expr	{ $$ = zend_ast_create_binary_op(ZEND_DIV, $1, $3); }
939 	|	expr '%' expr 	{ $$ = zend_ast_create_binary_op(ZEND_MOD, $1, $3); }
940 	| 	expr T_SL expr	{ $$ = zend_ast_create_binary_op(ZEND_SL, $1, $3); }
941 	|	expr T_SR expr	{ $$ = zend_ast_create_binary_op(ZEND_SR, $1, $3); }
942 	|	'+' expr %prec '~' { $$ = zend_ast_create(ZEND_AST_UNARY_PLUS, $2); }
943 	|	'-' expr %prec '~' { $$ = zend_ast_create(ZEND_AST_UNARY_MINUS, $2); }
944 	|	'!' expr { $$ = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BOOL_NOT, $2); }
945 	|	'~' expr { $$ = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BW_NOT, $2); }
946 	|	expr T_IS_IDENTICAL expr
947 			{ $$ = zend_ast_create_binary_op(ZEND_IS_IDENTICAL, $1, $3); }
948 	|	expr T_IS_NOT_IDENTICAL expr
949 			{ $$ = zend_ast_create_binary_op(ZEND_IS_NOT_IDENTICAL, $1, $3); }
950 	|	expr T_IS_EQUAL expr
951 			{ $$ = zend_ast_create_binary_op(ZEND_IS_EQUAL, $1, $3); }
952 	|	expr T_IS_NOT_EQUAL expr
953 			{ $$ = zend_ast_create_binary_op(ZEND_IS_NOT_EQUAL, $1, $3); }
954 	|	expr '<' expr
955 			{ $$ = zend_ast_create_binary_op(ZEND_IS_SMALLER, $1, $3); }
956 	|	expr T_IS_SMALLER_OR_EQUAL expr
957 			{ $$ = zend_ast_create_binary_op(ZEND_IS_SMALLER_OR_EQUAL, $1, $3); }
958 	|	expr '>' expr
959 			{ $$ = zend_ast_create(ZEND_AST_GREATER, $1, $3); }
960 	|	expr T_IS_GREATER_OR_EQUAL expr
961 			{ $$ = zend_ast_create(ZEND_AST_GREATER_EQUAL, $1, $3); }
962 	|	expr T_SPACESHIP expr
963 			{ $$ = zend_ast_create_binary_op(ZEND_SPACESHIP, $1, $3); }
964 	|	expr T_INSTANCEOF class_name_reference
965 			{ $$ = zend_ast_create(ZEND_AST_INSTANCEOF, $1, $3); }
966 	|	'(' expr ')' {
967 			$$ = $2;
968 			if ($$->kind == ZEND_AST_CONDITIONAL) $$->attr = ZEND_PARENTHESIZED_CONDITIONAL;
969 			if ($$->kind == ZEND_AST_BINARY_OP && $$->attr == ZEND_CONCAT) $$->attr = ZEND_PARENTHESIZED_CONCAT;
970 		}
971 	|	new_expr { $$ = $1; }
972 	|	expr '?' expr ':' expr
973 			{ $$ = zend_ast_create(ZEND_AST_CONDITIONAL, $1, $3, $5); }
974 	|	expr '?' ':' expr
975 			{ $$ = zend_ast_create(ZEND_AST_CONDITIONAL, $1, NULL, $4); }
976 	|	expr T_COALESCE expr
977 			{ $$ = zend_ast_create(ZEND_AST_COALESCE, $1, $3); }
978 	|	internal_functions_in_yacc { $$ = $1; }
979 	|	T_INT_CAST expr		{ $$ = zend_ast_create_cast(IS_LONG, $2); }
980 	|	T_DOUBLE_CAST expr	{ $$ = zend_ast_create_cast(IS_DOUBLE, $2); }
981 	|	T_STRING_CAST expr	{ $$ = zend_ast_create_cast(IS_STRING, $2); }
982 	|	T_ARRAY_CAST expr	{ $$ = zend_ast_create_cast(IS_ARRAY, $2); }
983 	|	T_OBJECT_CAST expr	{ $$ = zend_ast_create_cast(IS_OBJECT, $2); }
984 	|	T_BOOL_CAST expr	{ $$ = zend_ast_create_cast(_IS_BOOL, $2); }
985 	|	T_UNSET_CAST expr	{ $$ = zend_ast_create_cast(IS_NULL, $2); }
986 	|	T_EXIT exit_expr	{ $$ = zend_ast_create(ZEND_AST_EXIT, $2); }
987 	|	'@' expr			{ $$ = zend_ast_create(ZEND_AST_SILENCE, $2); }
988 	|	scalar { $$ = $1; }
989 	|	'`' backticks_expr '`' { $$ = zend_ast_create(ZEND_AST_SHELL_EXEC, $2); }
990 	|	T_PRINT expr { $$ = zend_ast_create(ZEND_AST_PRINT, $2); }
991 	|	T_YIELD { $$ = zend_ast_create(ZEND_AST_YIELD, NULL, NULL); CG(extra_fn_flags) |= ZEND_ACC_GENERATOR; }
992 	|	T_YIELD expr { $$ = zend_ast_create(ZEND_AST_YIELD, $2, NULL); CG(extra_fn_flags) |= ZEND_ACC_GENERATOR; }
993 	|	T_YIELD expr T_DOUBLE_ARROW expr { $$ = zend_ast_create(ZEND_AST_YIELD, $4, $2); CG(extra_fn_flags) |= ZEND_ACC_GENERATOR; }
994 	|	T_YIELD_FROM expr { $$ = zend_ast_create(ZEND_AST_YIELD_FROM, $2); CG(extra_fn_flags) |= ZEND_ACC_GENERATOR; }
995 	|	inline_function { $$ = $1; }
996 	|	T_STATIC inline_function { $$ = $2; ((zend_ast_decl *) $$)->flags |= ZEND_ACC_STATIC; }
997 ;
998 
999 
1000 inline_function:
1001 		function returns_ref backup_doc_comment '(' parameter_list ')' lexical_vars return_type
1002 		backup_fn_flags '{' inner_statement_list '}' backup_fn_flags
1003 			{ $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2 | $13, $1, $3,
1004 				  zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
1005 				  $5, $7, $11, $8); CG(extra_fn_flags) = $9; }
1006 	|	fn returns_ref '(' parameter_list ')' return_type backup_doc_comment T_DOUBLE_ARROW backup_fn_flags backup_lex_pos expr backup_fn_flags
1007 			{ $$ = zend_ast_create_decl(ZEND_AST_ARROW_FUNC, $2 | $12, $1, $7,
1008 				  zend_string_init("{closure}", sizeof("{closure}") - 1, 0), $4, NULL,
1009 				  zend_ast_create(ZEND_AST_RETURN, $11), $6);
1010 				  ((zend_ast_decl *) $$)->lex_pos = $10;
1011 				  CG(extra_fn_flags) = $9; }
1012 ;
1013 
1014 fn:
1015 	T_FN { $$ = CG(zend_lineno); }
1016 ;
1017 
1018 function:
1019 	T_FUNCTION { $$ = CG(zend_lineno); }
1020 ;
1021 
1022 backup_doc_comment:
1023 	/* empty */ { $$ = CG(doc_comment); CG(doc_comment) = NULL; }
1024 ;
1025 
1026 backup_fn_flags:
1027 	%prec PREC_ARROW_FUNCTION /* empty */ { $$ = CG(extra_fn_flags); CG(extra_fn_flags) = 0; }
1028 ;
1029 
1030 backup_lex_pos:
1031 	/* empty */ { $$ = LANG_SCNG(yy_text); }
1032 ;
1033 
1034 returns_ref:
1035 		/* empty */	{ $$ = 0; }
1036 	|	'&'			{ $$ = ZEND_ACC_RETURN_REFERENCE; }
1037 ;
1038 
1039 lexical_vars:
1040 		/* empty */ { $$ = NULL; }
1041 	|	T_USE '(' lexical_var_list ')' { $$ = $3; }
1042 ;
1043 
1044 lexical_var_list:
1045 		lexical_var_list ',' lexical_var { $$ = zend_ast_list_add($1, $3); }
1046 	|	lexical_var { $$ = zend_ast_create_list(1, ZEND_AST_CLOSURE_USES, $1); }
1047 ;
1048 
1049 lexical_var:
1050 		T_VARIABLE		{ $$ = $1; }
1051 	|	'&' T_VARIABLE	{ $$ = $2; $$->attr = ZEND_BIND_REF; }
1052 ;
1053 
1054 function_call:
1055 		name argument_list
1056 			{ $$ = zend_ast_create(ZEND_AST_CALL, $1, $2); }
1057 	|	class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
1058 			{ $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); }
1059 	|	variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
1060 			{ $$ = zend_ast_create(ZEND_AST_STATIC_CALL, $1, $3, $4); }
1061 	|	callable_expr argument_list
1062 			{ $$ = zend_ast_create(ZEND_AST_CALL, $1, $2); }
1063 ;
1064 
1065 class_name:
1066 		T_STATIC
1067 			{ zval zv; ZVAL_INTERNED_STR(&zv, ZSTR_KNOWN(ZEND_STR_STATIC));
1068 			  $$ = zend_ast_create_zval_ex(&zv, ZEND_NAME_NOT_FQ); }
1069 	|	name { $$ = $1; }
1070 ;
1071 
1072 class_name_reference:
1073 		class_name		{ $$ = $1; }
1074 	|	new_variable	{ $$ = $1; }
1075 ;
1076 
1077 exit_expr:
1078 		/* empty */				{ $$ = NULL; }
1079 	|	'(' optional_expr ')'	{ $$ = $2; }
1080 ;
1081 
1082 backticks_expr:
1083 		/* empty */
1084 			{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
1085 	|	T_ENCAPSED_AND_WHITESPACE { $$ = $1; }
1086 	|	encaps_list { $$ = $1; }
1087 ;
1088 
1089 
1090 ctor_arguments:
1091 		/* empty */	{ $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); }
1092 	|	argument_list { $$ = $1; }
1093 ;
1094 
1095 
1096 dereferencable_scalar:
1097 		T_ARRAY '(' array_pair_list ')'	{ $$ = $3; $$->attr = ZEND_ARRAY_SYNTAX_LONG; }
1098 	|	'[' array_pair_list ']'			{ $$ = $2; $$->attr = ZEND_ARRAY_SYNTAX_SHORT; }
1099 	|	T_CONSTANT_ENCAPSED_STRING		{ $$ = $1; }
1100 ;
1101 
1102 scalar:
1103 		T_LNUMBER 	{ $$ = $1; }
1104 	|	T_DNUMBER 	{ $$ = $1; }
1105 	|	T_LINE 		{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_LINE); }
1106 	|	T_FILE 		{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FILE); }
1107 	|	T_DIR   	{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_DIR); }
1108 	|	T_TRAIT_C	{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_TRAIT_C); }
1109 	|	T_METHOD_C	{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_METHOD_C); }
1110 	|	T_FUNC_C	{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FUNC_C); }
1111 	|	T_NS_C		{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_NS_C); }
1112 	|	T_CLASS_C	{ $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C); }
1113 	|	T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $2; }
1114 	|	T_START_HEREDOC T_END_HEREDOC
1115 			{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
1116 	|	'"' encaps_list '"' 	{ $$ = $2; }
1117 	|	T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $2; }
1118 	|	dereferencable_scalar	{ $$ = $1; }
1119 	|	constant			{ $$ = $1; }
1120 ;
1121 
1122 constant:
1123 		name { $$ = zend_ast_create(ZEND_AST_CONST, $1); }
1124 	|	class_name T_PAAMAYIM_NEKUDOTAYIM identifier
1125 			{ $$ = zend_ast_create_class_const_or_name($1, $3); }
1126 	|	variable_class_name T_PAAMAYIM_NEKUDOTAYIM identifier
1127 			{ $$ = zend_ast_create_class_const_or_name($1, $3); }
1128 ;
1129 
1130 optional_expr:
1131 		/* empty */	{ $$ = NULL; }
1132 	|	expr		{ $$ = $1; }
1133 ;
1134 
1135 variable_class_name:
1136 	dereferencable { $$ = $1; }
1137 ;
1138 
1139 dereferencable:
1140 		variable				{ $$ = $1; }
1141 	|	'(' expr ')'			{ $$ = $2; }
1142 	|	dereferencable_scalar	{ $$ = $1; }
1143 ;
1144 
1145 callable_expr:
1146 		callable_variable		{ $$ = $1; }
1147 	|	'(' expr ')'			{ $$ = $2; }
1148 	|	dereferencable_scalar	{ $$ = $1; }
1149 ;
1150 
1151 callable_variable:
1152 		simple_variable
1153 			{ $$ = zend_ast_create(ZEND_AST_VAR, $1); }
1154 	|	dereferencable '[' optional_expr ']'
1155 			{ $$ = zend_ast_create(ZEND_AST_DIM, $1, $3); }
1156 	|	constant '[' optional_expr ']'
1157 			{ $$ = zend_ast_create(ZEND_AST_DIM, $1, $3); }
1158 	|	dereferencable '{' expr '}'
1159 			{ $$ = zend_ast_create_ex(ZEND_AST_DIM, ZEND_DIM_ALTERNATIVE_SYNTAX, $1, $3); }
1160 	|	dereferencable T_OBJECT_OPERATOR property_name argument_list
1161 			{ $$ = zend_ast_create(ZEND_AST_METHOD_CALL, $1, $3, $4); }
1162 	|	function_call { $$ = $1; }
1163 ;
1164 
1165 variable:
1166 		callable_variable
1167 			{ $$ = $1; }
1168 	|	static_member
1169 			{ $$ = $1; }
1170 	|	dereferencable T_OBJECT_OPERATOR property_name
1171 			{ $$ = zend_ast_create(ZEND_AST_PROP, $1, $3); }
1172 ;
1173 
1174 simple_variable:
1175 		T_VARIABLE			{ $$ = $1; }
1176 	|	'$' '{' expr '}'	{ $$ = $3; }
1177 	|	'$' simple_variable	{ $$ = zend_ast_create(ZEND_AST_VAR, $2); }
1178 ;
1179 
1180 static_member:
1181 		class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
1182 			{ $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); }
1183 	|	variable_class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
1184 			{ $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); }
1185 ;
1186 
1187 new_variable:
1188 		simple_variable
1189 			{ $$ = zend_ast_create(ZEND_AST_VAR, $1); }
1190 	|	new_variable '[' optional_expr ']'
1191 			{ $$ = zend_ast_create(ZEND_AST_DIM, $1, $3); }
1192 	|	new_variable '{' expr '}'
1193 			{ $$ = zend_ast_create_ex(ZEND_AST_DIM, ZEND_DIM_ALTERNATIVE_SYNTAX, $1, $3); }
1194 	|	new_variable T_OBJECT_OPERATOR property_name
1195 			{ $$ = zend_ast_create(ZEND_AST_PROP, $1, $3); }
1196 	|	class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
1197 			{ $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); }
1198 	|	new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable
1199 			{ $$ = zend_ast_create(ZEND_AST_STATIC_PROP, $1, $3); }
1200 ;
1201 
1202 member_name:
1203 		identifier { $$ = $1; }
1204 	|	'{' expr '}'	{ $$ = $2; }
1205 	|	simple_variable	{ $$ = zend_ast_create(ZEND_AST_VAR, $1); }
1206 ;
1207 
1208 property_name:
1209 		T_STRING { $$ = $1; }
1210 	|	'{' expr '}'	{ $$ = $2; }
1211 	|	simple_variable	{ $$ = zend_ast_create(ZEND_AST_VAR, $1); }
1212 ;
1213 
1214 array_pair_list:
1215 		non_empty_array_pair_list
1216 			{ /* allow single trailing comma */ $$ = zend_ast_list_rtrim($1); }
1217 ;
1218 
1219 possible_array_pair:
1220 		/* empty */ { $$ = NULL; }
1221 	|	array_pair  { $$ = $1; }
1222 ;
1223 
1224 non_empty_array_pair_list:
1225 		non_empty_array_pair_list ',' possible_array_pair
1226 			{ $$ = zend_ast_list_add($1, $3); }
1227 	|	possible_array_pair
1228 			{ $$ = zend_ast_create_list(1, ZEND_AST_ARRAY, $1); }
1229 ;
1230 
1231 array_pair:
1232 		expr T_DOUBLE_ARROW expr
1233 			{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, $1); }
1234 	|	expr
1235 			{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $1, NULL); }
1236 	|	expr T_DOUBLE_ARROW '&' variable
1237 			{ $$ = zend_ast_create_ex(ZEND_AST_ARRAY_ELEM, 1, $4, $1); }
1238 	|	'&' variable
1239 			{ $$ = zend_ast_create_ex(ZEND_AST_ARRAY_ELEM, 1, $2, NULL); }
1240 	|	T_ELLIPSIS expr
1241 			{ $$ = zend_ast_create(ZEND_AST_UNPACK, $2); }
1242 	|	expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')'
1243 			{ $5->attr = ZEND_ARRAY_SYNTAX_LIST;
1244 			  $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $5, $1); }
1245 	|	T_LIST '(' array_pair_list ')'
1246 			{ $3->attr = ZEND_ARRAY_SYNTAX_LIST;
1247 			  $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, NULL); }
1248 ;
1249 
1250 encaps_list:
1251 		encaps_list encaps_var
1252 			{ $$ = zend_ast_list_add($1, $2); }
1253 	|	encaps_list T_ENCAPSED_AND_WHITESPACE
1254 			{ $$ = zend_ast_list_add($1, $2); }
1255 	|	encaps_var
1256 			{ $$ = zend_ast_create_list(1, ZEND_AST_ENCAPS_LIST, $1); }
1257 	|	T_ENCAPSED_AND_WHITESPACE encaps_var
1258 			{ $$ = zend_ast_create_list(2, ZEND_AST_ENCAPS_LIST, $1, $2); }
1259 ;
1260 
1261 encaps_var:
1262 		T_VARIABLE
1263 			{ $$ = zend_ast_create(ZEND_AST_VAR, $1); }
1264 	|	T_VARIABLE '[' encaps_var_offset ']'
1265 			{ $$ = zend_ast_create(ZEND_AST_DIM,
1266 			      zend_ast_create(ZEND_AST_VAR, $1), $3); }
1267 	|	T_VARIABLE T_OBJECT_OPERATOR T_STRING
1268 			{ $$ = zend_ast_create(ZEND_AST_PROP,
1269 			      zend_ast_create(ZEND_AST_VAR, $1), $3); }
1270 	|	T_DOLLAR_OPEN_CURLY_BRACES expr '}'
1271 			{ $$ = zend_ast_create(ZEND_AST_VAR, $2); }
1272 	|	T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'
1273 			{ $$ = zend_ast_create(ZEND_AST_VAR, $2); }
1274 	|	T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
1275 			{ $$ = zend_ast_create(ZEND_AST_DIM,
1276 			      zend_ast_create(ZEND_AST_VAR, $2), $4); }
1277 	|	T_CURLY_OPEN variable '}' { $$ = $2; }
1278 ;
1279 
1280 encaps_var_offset:
1281 		T_STRING			{ $$ = $1; }
1282 	|	T_NUM_STRING		{ $$ = $1; }
1283 	|	'-' T_NUM_STRING 	{ $$ = zend_negate_num_string($2); }
1284 	|	T_VARIABLE			{ $$ = zend_ast_create(ZEND_AST_VAR, $1); }
1285 ;
1286 
1287 
1288 internal_functions_in_yacc:
1289 		T_ISSET '(' isset_variables possible_comma ')' { $$ = $3; }
1290 	|	T_EMPTY '(' expr ')' { $$ = zend_ast_create(ZEND_AST_EMPTY, $3); }
1291 	|	T_INCLUDE expr
1292 			{ $$ = zend_ast_create_ex(ZEND_AST_INCLUDE_OR_EVAL, ZEND_INCLUDE, $2); }
1293 	|	T_INCLUDE_ONCE expr
1294 			{ $$ = zend_ast_create_ex(ZEND_AST_INCLUDE_OR_EVAL, ZEND_INCLUDE_ONCE, $2); }
1295 	|	T_EVAL '(' expr ')'
1296 			{ $$ = zend_ast_create_ex(ZEND_AST_INCLUDE_OR_EVAL, ZEND_EVAL, $3); }
1297 	|	T_REQUIRE expr
1298 			{ $$ = zend_ast_create_ex(ZEND_AST_INCLUDE_OR_EVAL, ZEND_REQUIRE, $2); }
1299 	|	T_REQUIRE_ONCE expr
1300 			{ $$ = zend_ast_create_ex(ZEND_AST_INCLUDE_OR_EVAL, ZEND_REQUIRE_ONCE, $2); }
1301 ;
1302 
1303 isset_variables:
1304 		isset_variable { $$ = $1; }
1305 	|	isset_variables ',' isset_variable
1306 			{ $$ = zend_ast_create(ZEND_AST_AND, $1, $3); }
1307 ;
1308 
1309 isset_variable:
1310 		expr { $$ = zend_ast_create(ZEND_AST_ISSET, $1); }
1311 ;
1312 
1313 %%
1314 
1315 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1316    quotes and backslashes, so that it's suitable for yyerror.  The
1317    heuristic is that double-quoting is unnecessary unless the string
1318    contains an apostrophe, a comma, or backslash (other than
1319    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1320    null, do not copy; instead, return the length of what the result
1321    would have been.  */
1322 static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr)
1323 {
1324 	/* CG(parse_error) states:
1325 	 * 0 => yyres = NULL, yystr is the unexpected token
1326 	 * 1 => yyres = NULL, yystr is one of the expected tokens
1327 	 * 2 => yyres != NULL, yystr is the unexpected token
1328 	 * 3 => yyres != NULL, yystr is one of the expected tokens
1329 	 */
1330 	if (yyres && CG(parse_error) < 2) {
1331 		CG(parse_error) = 2;
1332 	}
1333 
1334 	if (CG(parse_error) % 2 == 0) {
1335 		/* The unexpected token */
1336 		char buffer[120];
1337 		const unsigned char *end, *str, *tok1 = NULL, *tok2 = NULL;
1338 		unsigned int len = 0, toklen = 0, yystr_len;
1339 
1340 		CG(parse_error)++;
1341 
1342 		if (LANG_SCNG(yy_text)[0] == 0 &&
1343 			LANG_SCNG(yy_leng) == 1 &&
1344 			strcmp(yystr, "\"end of file\"") == 0) {
1345 			if (yyres) {
1346 				yystpcpy(yyres, "end of file");
1347 			}
1348 			return sizeof("end of file")-1;
1349 		}
1350 
1351 		str = LANG_SCNG(yy_text);
1352 		end = memchr(str, '\n', LANG_SCNG(yy_leng));
1353 		yystr_len = (unsigned int)yystrlen(yystr);
1354 
1355 		if ((tok1 = memchr(yystr, '(', yystr_len)) != NULL
1356 			&& (tok2 = zend_memrchr(yystr, ')', yystr_len)) != NULL) {
1357 			toklen = (tok2 - tok1) + 1;
1358 		} else {
1359 			tok1 = tok2 = NULL;
1360 			toklen = 0;
1361 		}
1362 
1363 		if (end == NULL) {
1364 			len = LANG_SCNG(yy_leng) > 30 ? 30 : LANG_SCNG(yy_leng);
1365 		} else {
1366 			len = (end - str) > 30 ? 30 : (end - str);
1367 		}
1368 		if (yyres) {
1369 			if (toklen) {
1370 				snprintf(buffer, sizeof(buffer), "'%.*s' %.*s", len, str, toklen, tok1);
1371 			} else {
1372 				snprintf(buffer, sizeof(buffer), "'%.*s'", len, str);
1373 			}
1374 			yystpcpy(yyres, buffer);
1375 		}
1376 		return len + (toklen ? toklen + 1 : 0) + 2;
1377 	}
1378 
1379 	/* One of the expected tokens */
1380 	if (!yyres) {
1381 		return yystrlen(yystr) - (*yystr == '"' ? 2 : 0);
1382 	}
1383 
1384 	if (*yystr == '"') {
1385 		YYSIZE_T yyn = 0;
1386 		const char *yyp = yystr;
1387 
1388 		for (; *++yyp != '"'; ++yyn) {
1389 			yyres[yyn] = *yyp;
1390 		}
1391 		yyres[yyn] = '\0';
1392 		return yyn;
1393 	}
1394 	yystpcpy(yyres, yystr);
1395 	return strlen(yystr);
1396 }
1397