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