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