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