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