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