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