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