Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
%pure_parser
2
%expect 6
3
 
4
%tokens
5
 
6
%%
7
 
8
start:
9
    top_statement_list                                      { $$ = $this->handleNamespaces($1); }
10
;
11
 
12
top_statement_list_ex:
13
      top_statement_list_ex top_statement                   { pushNormalizing($1, $2); }
14
    | /* empty */                                           { init(); }
15
;
16
 
17
top_statement_list:
18
      top_statement_list_ex
19
          { makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
20
            if ($nop !== null) { $1[] = $nop; } $$ = $1; }
21
;
22
 
23
ampersand:
24
      T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
25
    | T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG
26
;
27
 
28
reserved_non_modifiers:
29
      T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND
30
    | T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE
31
    | T_ENDWHILE | T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH
32
    | T_FINALLY | T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
33
    | T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT
34
    | T_BREAK | T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
35
    | T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_HALT_COMPILER | T_FN
36
    | T_MATCH
37
;
38
 
39
semi_reserved:
40
      reserved_non_modifiers
41
    | T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
42
;
43
 
44
identifier_ex:
45
      T_STRING                                              { $$ = Node\Identifier[$1]; }
46
    | semi_reserved                                         { $$ = Node\Identifier[$1]; }
47
;
48
 
49
identifier:
50
      T_STRING                                              { $$ = Node\Identifier[$1]; }
51
;
52
 
53
reserved_non_modifiers_identifier:
54
      reserved_non_modifiers                                { $$ = Node\Identifier[$1]; }
55
;
56
 
57
namespace_name:
58
      T_STRING                                              { $$ = Name[$1]; }
59
    | T_NAME_QUALIFIED                                      { $$ = Name[$1]; }
60
;
61
 
62
legacy_namespace_name:
63
      namespace_name                                        { $$ = $1; }
64
    | T_NAME_FULLY_QUALIFIED                                { $$ = Name[substr($1, 1)]; }
65
;
66
 
67
plain_variable:
68
      T_VARIABLE                                            { $$ = Expr\Variable[parseVar($1)]; }
69
;
70
 
71
top_statement:
72
      statement                                             { $$ = $1; }
73
    | function_declaration_statement                        { $$ = $1; }
74
    | class_declaration_statement                           { $$ = $1; }
75
    | T_HALT_COMPILER
76
          { $$ = Stmt\HaltCompiler[$this->lexer->handleHaltCompiler()]; }
77
    | T_NAMESPACE namespace_name ';'
78
          { $$ = Stmt\Namespace_[$2, null];
79
            $$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON);
80
            $this->checkNamespace($$); }
81
    | T_NAMESPACE namespace_name '{' top_statement_list '}'
82
          { $$ = Stmt\Namespace_[$2, $4];
83
            $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
84
            $this->checkNamespace($$); }
85
    | T_NAMESPACE '{' top_statement_list '}'
86
          { $$ = Stmt\Namespace_[null, $3];
87
            $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
88
            $this->checkNamespace($$); }
89
    | T_USE use_declarations ';'                            { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; }
90
    | T_USE use_type use_declarations ';'                   { $$ = Stmt\Use_[$3, $2]; }
91
    | group_use_declaration ';'                             { $$ = $1; }
92
    | T_CONST constant_declaration_list ';'                 { $$ = Stmt\Const_[$2]; }
93
;
94
 
95
use_type:
96
      T_FUNCTION                                            { $$ = Stmt\Use_::TYPE_FUNCTION; }
97
    | T_CONST                                               { $$ = Stmt\Use_::TYPE_CONSTANT; }
98
;
99
 
100
group_use_declaration:
101
      T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
102
          { $$ = Stmt\GroupUse[$3, $6, $2]; }
103
    | T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
104
          { $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; }
105
;
106
 
107
unprefixed_use_declarations:
108
      unprefixed_use_declarations ',' unprefixed_use_declaration
109
          { push($1, $3); }
110
    | unprefixed_use_declaration                            { init($1); }
111
;
112
 
113
use_declarations:
114
      use_declarations ',' use_declaration                  { push($1, $3); }
115
    | use_declaration                                       { init($1); }
116
;
117
 
118
inline_use_declarations:
119
      inline_use_declarations ',' inline_use_declaration    { push($1, $3); }
120
    | inline_use_declaration                                { init($1); }
121
;
122
 
123
unprefixed_use_declaration:
124
      namespace_name
125
          { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
126
    | namespace_name T_AS identifier
127
          { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
128
;
129
 
130
use_declaration:
131
      legacy_namespace_name
132
          { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
133
    | legacy_namespace_name T_AS identifier
134
          { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
135
;
136
 
137
inline_use_declaration:
138
      unprefixed_use_declaration                            { $$ = $1; $$->type = Stmt\Use_::TYPE_NORMAL; }
139
    | use_type unprefixed_use_declaration                   { $$ = $2; $$->type = $1; }
140
;
141
 
142
constant_declaration_list:
143
      constant_declaration_list ',' constant_declaration    { push($1, $3); }
144
    | constant_declaration                                  { init($1); }
145
;
146
 
147
constant_declaration:
148
    identifier '=' static_scalar                            { $$ = Node\Const_[$1, $3]; }
149
;
150
 
151
class_const_list:
152
      class_const_list ',' class_const                      { push($1, $3); }
153
    | class_const                                           { init($1); }
154
;
155
 
156
class_const:
157
    identifier_ex '=' static_scalar                         { $$ = Node\Const_[$1, $3]; }
158
;
159
 
160
inner_statement_list_ex:
161
      inner_statement_list_ex inner_statement               { pushNormalizing($1, $2); }
162
    | /* empty */                                           { init(); }
163
;
164
 
165
inner_statement_list:
166
      inner_statement_list_ex
167
          { makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
168
            if ($nop !== null) { $1[] = $nop; } $$ = $1; }
169
;
170
 
171
inner_statement:
172
      statement                                             { $$ = $1; }
173
    | function_declaration_statement                        { $$ = $1; }
174
    | class_declaration_statement                           { $$ = $1; }
175
    | T_HALT_COMPILER
176
          { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); }
177
;
178
 
179
non_empty_statement:
180
      '{' inner_statement_list '}'
181
    {
182
        if ($2) {
183
            $$ = $2; prependLeadingComments($$);
184
        } else {
185
            makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
186
            if (null === $$) { $$ = array(); }
187
        }
188
    }
189
    | T_IF parentheses_expr statement elseif_list else_single
190
          { $$ = Stmt\If_[$2, ['stmts' => toArray($3), 'elseifs' => $4, 'else' => $5]]; }
191
    | T_IF parentheses_expr ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
192
          { $$ = Stmt\If_[$2, ['stmts' => $4, 'elseifs' => $5, 'else' => $6]]; }
193
    | T_WHILE parentheses_expr while_statement              { $$ = Stmt\While_[$2, $3]; }
194
    | T_DO statement T_WHILE parentheses_expr ';'           { $$ = Stmt\Do_   [$4, toArray($2)]; }
195
    | T_FOR '(' for_expr ';'  for_expr ';' for_expr ')' for_statement
196
          { $$ = Stmt\For_[['init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => $9]]; }
197
    | T_SWITCH parentheses_expr switch_case_list            { $$ = Stmt\Switch_[$2, $3]; }
198
    | T_BREAK ';'                                           { $$ = Stmt\Break_[null]; }
199
    | T_BREAK expr ';'                                      { $$ = Stmt\Break_[$2]; }
200
    | T_CONTINUE ';'                                        { $$ = Stmt\Continue_[null]; }
201
    | T_CONTINUE expr ';'                                   { $$ = Stmt\Continue_[$2]; }
202
    | T_RETURN ';'                                          { $$ = Stmt\Return_[null]; }
203
    | T_RETURN expr ';'                                     { $$ = Stmt\Return_[$2]; }
204
    | T_GLOBAL global_var_list ';'                          { $$ = Stmt\Global_[$2]; }
205
    | T_STATIC static_var_list ';'                          { $$ = Stmt\Static_[$2]; }
206
    | T_ECHO expr_list ';'                                  { $$ = Stmt\Echo_[$2]; }
207
    | T_INLINE_HTML                                         { $$ = Stmt\InlineHTML[$1]; }
208
    | yield_expr ';'                                        { $$ = Stmt\Expression[$1]; }
209
    | expr ';'                                              { $$ = Stmt\Expression[$1]; }
210
    | T_UNSET '(' variables_list ')' ';'                    { $$ = Stmt\Unset_[$3]; }
211
    | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
212
          { $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; }
213
    | T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement
214
          { $$ = Stmt\Foreach_[$3, $7[0], ['keyVar' => $5, 'byRef' => $7[1], 'stmts' => $9]]; }
215
    | T_DECLARE '(' declare_list ')' declare_statement      { $$ = Stmt\Declare_[$3, $5]; }
216
    | T_TRY '{' inner_statement_list '}' catches optional_finally
217
          { $$ = Stmt\TryCatch[$3, $5, $6]; $this->checkTryCatch($$); }
218
    | T_THROW expr ';'                                      { $$ = Stmt\Throw_[$2]; }
219
    | T_GOTO identifier ';'                                 { $$ = Stmt\Goto_[$2]; }
220
    | identifier ':'                                        { $$ = Stmt\Label[$1]; }
221
    | expr error                                            { $$ = Stmt\Expression[$1]; }
222
    | error                                                 { $$ = array(); /* means: no statement */ }
223
;
224
 
225
statement:
226
      non_empty_statement                                   { $$ = $1; }
227
    | ';'
228
          { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
229
            if ($$ === null) $$ = array(); /* means: no statement */ }
230
;
231
 
232
catches:
233
      /* empty */                                           { init(); }
234
    | catches catch                                         { push($1, $2); }
235
;
236
 
237
catch:
238
    T_CATCH '(' name plain_variable ')' '{' inner_statement_list '}'
239
        { $$ = Stmt\Catch_[array($3), $4, $7]; }
240
;
241
 
242
optional_finally:
243
      /* empty */                                           { $$ = null; }
244
    | T_FINALLY '{' inner_statement_list '}'                { $$ = Stmt\Finally_[$3]; }
245
;
246
 
247
variables_list:
248
      variable                                              { init($1); }
249
    | variables_list ',' variable                           { push($1, $3); }
250
;
251
 
252
optional_ref:
253
      /* empty */                                           { $$ = false; }
254
    | ampersand                                             { $$ = true; }
255
;
256
 
257
optional_arg_ref:
258
      /* empty */                                           { $$ = false; }
259
    | T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG                 { $$ = true; }
260
;
261
 
262
optional_ellipsis:
263
      /* empty */                                           { $$ = false; }
264
    | T_ELLIPSIS                                            { $$ = true; }
265
;
266
 
150 lars 267
identifier_maybe_readonly:
268
      identifier                                            { $$ = $1; }
269
    | T_READONLY                                            { $$ = Node\Identifier[$1]; }
270
;
271
 
148 lars 272
function_declaration_statement:
150 lars 273
    T_FUNCTION optional_ref identifier_maybe_readonly '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
148 lars 274
        { $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
275
;
276
 
277
class_declaration_statement:
278
      class_entry_type identifier extends_from implements_list '{' class_statement_list '}'
279
          { $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6]];
280
            $this->checkClass($$, #2); }
281
    | T_INTERFACE identifier interface_extends_list '{' class_statement_list '}'
282
          { $$ = Stmt\Interface_[$2, ['extends' => $3, 'stmts' => $5]];
283
            $this->checkInterface($$, #2); }
284
    | T_TRAIT identifier '{' class_statement_list '}'
285
          { $$ = Stmt\Trait_[$2, ['stmts' => $4]]; }
286
;
287
 
288
class_entry_type:
289
      T_CLASS                                               { $$ = 0; }
290
    | T_ABSTRACT T_CLASS                                    { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
291
    | T_FINAL T_CLASS                                       { $$ = Stmt\Class_::MODIFIER_FINAL; }
292
;
293
 
294
extends_from:
295
      /* empty */                                           { $$ = null; }
296
    | T_EXTENDS class_name                                  { $$ = $2; }
297
;
298
 
299
interface_extends_list:
300
      /* empty */                                           { $$ = array(); }
301
    | T_EXTENDS class_name_list                             { $$ = $2; }
302
;
303
 
304
implements_list:
305
      /* empty */                                           { $$ = array(); }
306
    | T_IMPLEMENTS class_name_list                          { $$ = $2; }
307
;
308
 
309
class_name_list:
310
      class_name                                            { init($1); }
311
    | class_name_list ',' class_name                        { push($1, $3); }
312
;
313
 
314
for_statement:
315
      statement                                             { $$ = toArray($1); }
316
    | ':' inner_statement_list T_ENDFOR ';'                 { $$ = $2; }
317
;
318
 
319
foreach_statement:
320
      statement                                             { $$ = toArray($1); }
321
    | ':' inner_statement_list T_ENDFOREACH ';'             { $$ = $2; }
322
;
323
 
324
declare_statement:
325
      non_empty_statement                                   { $$ = toArray($1); }
326
    | ';'                                                   { $$ = null; }
327
    | ':' inner_statement_list T_ENDDECLARE ';'             { $$ = $2; }
328
;
329
 
330
declare_list:
331
      declare_list_element                                  { init($1); }
332
    | declare_list ',' declare_list_element                 { push($1, $3); }
333
;
334
 
335
declare_list_element:
336
      identifier '=' static_scalar                          { $$ = Stmt\DeclareDeclare[$1, $3]; }
337
;
338
 
339
switch_case_list:
340
      '{' case_list '}'                                     { $$ = $2; }
341
    | '{' ';' case_list '}'                                 { $$ = $3; }
342
    | ':' case_list T_ENDSWITCH ';'                         { $$ = $2; }
343
    | ':' ';' case_list T_ENDSWITCH ';'                     { $$ = $3; }
344
;
345
 
346
case_list:
347
      /* empty */                                           { init(); }
348
    | case_list case                                        { push($1, $2); }
349
;
350
 
351
case:
352
      T_CASE expr case_separator inner_statement_list_ex    { $$ = Stmt\Case_[$2, $4]; }
353
    | T_DEFAULT case_separator inner_statement_list_ex      { $$ = Stmt\Case_[null, $3]; }
354
;
355
 
356
case_separator:
357
      ':'
358
    | ';'
359
;
360
 
361
while_statement:
362
      statement                                             { $$ = toArray($1); }
363
    | ':' inner_statement_list T_ENDWHILE ';'               { $$ = $2; }
364
;
365
 
366
elseif_list:
367
      /* empty */                                           { init(); }
368
    | elseif_list elseif                                    { push($1, $2); }
369
;
370
 
371
elseif:
372
      T_ELSEIF parentheses_expr statement                   { $$ = Stmt\ElseIf_[$2, toArray($3)]; }
373
;
374
 
375
new_elseif_list:
376
      /* empty */                                           { init(); }
377
    | new_elseif_list new_elseif                            { push($1, $2); }
378
;
379
 
380
new_elseif:
381
     T_ELSEIF parentheses_expr ':' inner_statement_list     { $$ = Stmt\ElseIf_[$2, $4]; }
382
;
383
 
384
else_single:
385
      /* empty */                                           { $$ = null; }
386
    | T_ELSE statement                                      { $$ = Stmt\Else_[toArray($2)]; }
387
;
388
 
389
new_else_single:
390
      /* empty */                                           { $$ = null; }
391
    | T_ELSE ':' inner_statement_list                       { $$ = Stmt\Else_[$3]; }
392
;
393
 
394
foreach_variable:
395
      variable                                              { $$ = array($1, false); }
396
    | ampersand variable                                    { $$ = array($2, true); }
397
    | list_expr                                             { $$ = array($1, false); }
398
;
399
 
400
parameter_list:
401
      non_empty_parameter_list                              { $$ = $1; }
402
    | /* empty */                                           { $$ = array(); }
403
;
404
 
405
non_empty_parameter_list:
406
      parameter                                             { init($1); }
407
    | non_empty_parameter_list ',' parameter                { push($1, $3); }
408
;
409
 
410
parameter:
411
      optional_param_type optional_arg_ref optional_ellipsis plain_variable
412
          { $$ = Node\Param[$4, null, $1, $2, $3]; $this->checkParam($$); }
413
    | optional_param_type optional_arg_ref optional_ellipsis plain_variable '=' static_scalar
414
          { $$ = Node\Param[$4, $6, $1, $2, $3]; $this->checkParam($$); }
415
;
416
 
417
type:
418
      name                                                  { $$ = $1; }
419
    | T_ARRAY                                               { $$ = Node\Identifier['array']; }
420
    | T_CALLABLE                                            { $$ = Node\Identifier['callable']; }
421
;
422
 
423
optional_param_type:
424
      /* empty */                                           { $$ = null; }
425
    | type                                                  { $$ = $1; }
426
;
427
 
428
optional_return_type:
429
      /* empty */                                           { $$ = null; }
430
    | ':' type                                              { $$ = $2; }
431
;
432
 
433
argument_list:
434
      '(' ')'                                               { $$ = array(); }
435
    | '(' non_empty_argument_list ')'                       { $$ = $2; }
436
    | '(' yield_expr ')'                                    { $$ = array(Node\Arg[$2, false, false]); }
437
;
438
 
439
non_empty_argument_list:
440
      argument                                              { init($1); }
441
    | non_empty_argument_list ',' argument                  { push($1, $3); }
442
;
443
 
444
argument:
445
      expr                                                  { $$ = Node\Arg[$1, false, false]; }
446
    | ampersand variable                                    { $$ = Node\Arg[$2, true, false]; }
447
    | T_ELLIPSIS expr                                       { $$ = Node\Arg[$2, false, true]; }
448
;
449
 
450
global_var_list:
451
      global_var_list ',' global_var                        { push($1, $3); }
452
    | global_var                                            { init($1); }
453
;
454
 
455
global_var:
456
      plain_variable                                        { $$ = $1; }
457
    | '$' variable                                          { $$ = Expr\Variable[$2]; }
458
    | '$' '{' expr '}'                                      { $$ = Expr\Variable[$3]; }
459
;
460
 
461
static_var_list:
462
      static_var_list ',' static_var                        { push($1, $3); }
463
    | static_var                                            { init($1); }
464
;
465
 
466
static_var:
467
      plain_variable                                        { $$ = Stmt\StaticVar[$1, null]; }
468
    | plain_variable '=' static_scalar                      { $$ = Stmt\StaticVar[$1, $3]; }
469
;
470
 
471
class_statement_list_ex:
472
      class_statement_list_ex class_statement               { if ($2 !== null) { push($1, $2); } }
473
    | /* empty */                                           { init(); }
474
;
475
 
476
class_statement_list:
477
      class_statement_list_ex
478
          { makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
479
            if ($nop !== null) { $1[] = $nop; } $$ = $1; }
480
;
481
 
482
class_statement:
483
      variable_modifiers property_declaration_list ';'
484
          { $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); }
485
    | T_CONST class_const_list ';'                          { $$ = Stmt\ClassConst[$2, 0]; }
486
    | method_modifiers T_FUNCTION optional_ref identifier_ex '(' parameter_list ')' optional_return_type method_body
487
          { $$ = Stmt\ClassMethod[$4, ['type' => $1, 'byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9]];
488
            $this->checkClassMethod($$, #1); }
489
    | T_USE class_name_list trait_adaptations               { $$ = Stmt\TraitUse[$2, $3]; }
490
;
491
 
492
trait_adaptations:
493
      ';'                                                   { $$ = array(); }
494
    | '{' trait_adaptation_list '}'                         { $$ = $2; }
495
;
496
 
497
trait_adaptation_list:
498
      /* empty */                                           { init(); }
499
    | trait_adaptation_list trait_adaptation                { push($1, $2); }
500
;
501
 
502
trait_adaptation:
503
      trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';'
504
          { $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; }
505
    | trait_method_reference T_AS member_modifier identifier_ex ';'
506
          { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; }
507
    | trait_method_reference T_AS member_modifier ';'
508
          { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; }
509
    | trait_method_reference T_AS identifier ';'
510
          { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
511
    | trait_method_reference T_AS reserved_non_modifiers_identifier ';'
512
          { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
513
;
514
 
515
trait_method_reference_fully_qualified:
516
      name T_PAAMAYIM_NEKUDOTAYIM identifier_ex             { $$ = array($1, $3); }
517
;
518
trait_method_reference:
519
      trait_method_reference_fully_qualified                { $$ = $1; }
520
    | identifier_ex                                         { $$ = array(null, $1); }
521
;
522
 
523
method_body:
524
      ';' /* abstract method */                             { $$ = null; }
525
    | '{' inner_statement_list '}'                          { $$ = $2; }
526
;
527
 
528
variable_modifiers:
529
      non_empty_member_modifiers                            { $$ = $1; }
530
    | T_VAR                                                 { $$ = 0; }
531
;
532
 
533
method_modifiers:
534
      /* empty */                                           { $$ = 0; }
535
    | non_empty_member_modifiers                            { $$ = $1; }
536
;
537
 
538
non_empty_member_modifiers:
539
      member_modifier                                       { $$ = $1; }
540
    | non_empty_member_modifiers member_modifier            { $this->checkModifier($1, $2, #2); $$ = $1 | $2; }
541
;
542
 
543
member_modifier:
544
      T_PUBLIC                                              { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
545
    | T_PROTECTED                                           { $$ = Stmt\Class_::MODIFIER_PROTECTED; }
546
    | T_PRIVATE                                             { $$ = Stmt\Class_::MODIFIER_PRIVATE; }
547
    | T_STATIC                                              { $$ = Stmt\Class_::MODIFIER_STATIC; }
548
    | T_ABSTRACT                                            { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
549
    | T_FINAL                                               { $$ = Stmt\Class_::MODIFIER_FINAL; }
550
;
551
 
552
property_declaration_list:
553
      property_declaration                                  { init($1); }
554
    | property_declaration_list ',' property_declaration    { push($1, $3); }
555
;
556
 
557
property_decl_name:
558
      T_VARIABLE                                            { $$ = Node\VarLikeIdentifier[parseVar($1)]; }
559
;
560
 
561
property_declaration:
562
      property_decl_name                                    { $$ = Stmt\PropertyProperty[$1, null]; }
563
    | property_decl_name '=' static_scalar                  { $$ = Stmt\PropertyProperty[$1, $3]; }
564
;
565
 
566
expr_list:
567
      expr_list ',' expr                                    { push($1, $3); }
568
    | expr                                                  { init($1); }
569
;
570
 
571
for_expr:
572
      /* empty */                                           { $$ = array(); }
573
    | expr_list                                             { $$ = $1; }
574
;
575
 
576
expr:
577
      variable                                              { $$ = $1; }
578
    | list_expr '=' expr                                    { $$ = Expr\Assign[$1, $3]; }
579
    | variable '=' expr                                     { $$ = Expr\Assign[$1, $3]; }
580
    | variable '=' ampersand variable                       { $$ = Expr\AssignRef[$1, $4]; }
581
    | variable '=' ampersand new_expr                       { $$ = Expr\AssignRef[$1, $4]; }
582
    | new_expr                                              { $$ = $1; }
583
    | T_CLONE expr                                          { $$ = Expr\Clone_[$2]; }
584
    | variable T_PLUS_EQUAL expr                            { $$ = Expr\AssignOp\Plus      [$1, $3]; }
585
    | variable T_MINUS_EQUAL expr                           { $$ = Expr\AssignOp\Minus     [$1, $3]; }
586
    | variable T_MUL_EQUAL expr                             { $$ = Expr\AssignOp\Mul       [$1, $3]; }
587
    | variable T_DIV_EQUAL expr                             { $$ = Expr\AssignOp\Div       [$1, $3]; }
588
    | variable T_CONCAT_EQUAL expr                          { $$ = Expr\AssignOp\Concat    [$1, $3]; }
589
    | variable T_MOD_EQUAL expr                             { $$ = Expr\AssignOp\Mod       [$1, $3]; }
590
    | variable T_AND_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseAnd[$1, $3]; }
591
    | variable T_OR_EQUAL expr                              { $$ = Expr\AssignOp\BitwiseOr [$1, $3]; }
592
    | variable T_XOR_EQUAL expr                             { $$ = Expr\AssignOp\BitwiseXor[$1, $3]; }
593
    | variable T_SL_EQUAL expr                              { $$ = Expr\AssignOp\ShiftLeft [$1, $3]; }
594
    | variable T_SR_EQUAL expr                              { $$ = Expr\AssignOp\ShiftRight[$1, $3]; }
595
    | variable T_POW_EQUAL expr                             { $$ = Expr\AssignOp\Pow       [$1, $3]; }
596
    | variable T_COALESCE_EQUAL expr                        { $$ = Expr\AssignOp\Coalesce  [$1, $3]; }
597
    | variable T_INC                                        { $$ = Expr\PostInc[$1]; }
598
    | T_INC variable                                        { $$ = Expr\PreInc [$2]; }
599
    | variable T_DEC                                        { $$ = Expr\PostDec[$1]; }
600
    | T_DEC variable                                        { $$ = Expr\PreDec [$2]; }
601
    | expr T_BOOLEAN_OR expr                                { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; }
602
    | expr T_BOOLEAN_AND expr                               { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; }
603
    | expr T_LOGICAL_OR expr                                { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; }
604
    | expr T_LOGICAL_AND expr                               { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; }
605
    | expr T_LOGICAL_XOR expr                               { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; }
606
    | expr '|' expr                                         { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; }
607
    | expr T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG expr   { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
608
    | expr T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG expr       { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
609
    | expr '^' expr                                         { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; }
610
    | expr '.' expr                                         { $$ = Expr\BinaryOp\Concat    [$1, $3]; }
611
    | expr '+' expr                                         { $$ = Expr\BinaryOp\Plus      [$1, $3]; }
612
    | expr '-' expr                                         { $$ = Expr\BinaryOp\Minus     [$1, $3]; }
613
    | expr '*' expr                                         { $$ = Expr\BinaryOp\Mul       [$1, $3]; }
614
    | expr '/' expr                                         { $$ = Expr\BinaryOp\Div       [$1, $3]; }
615
    | expr '%' expr                                         { $$ = Expr\BinaryOp\Mod       [$1, $3]; }
616
    | expr T_SL expr                                        { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; }
617
    | expr T_SR expr                                        { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; }
618
    | expr T_POW expr                                       { $$ = Expr\BinaryOp\Pow       [$1, $3]; }
619
    | '+' expr %prec T_INC                                  { $$ = Expr\UnaryPlus [$2]; }
620
    | '-' expr %prec T_INC                                  { $$ = Expr\UnaryMinus[$2]; }
621
    | '!' expr                                              { $$ = Expr\BooleanNot[$2]; }
622
    | '~' expr                                              { $$ = Expr\BitwiseNot[$2]; }
623
    | expr T_IS_IDENTICAL expr                              { $$ = Expr\BinaryOp\Identical     [$1, $3]; }
624
    | expr T_IS_NOT_IDENTICAL expr                          { $$ = Expr\BinaryOp\NotIdentical  [$1, $3]; }
625
    | expr T_IS_EQUAL expr                                  { $$ = Expr\BinaryOp\Equal         [$1, $3]; }
626
    | expr T_IS_NOT_EQUAL expr                              { $$ = Expr\BinaryOp\NotEqual      [$1, $3]; }
627
    | expr T_SPACESHIP expr                                 { $$ = Expr\BinaryOp\Spaceship     [$1, $3]; }
628
    | expr '<' expr                                         { $$ = Expr\BinaryOp\Smaller       [$1, $3]; }
629
    | expr T_IS_SMALLER_OR_EQUAL expr                       { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; }
630
    | expr '>' expr                                         { $$ = Expr\BinaryOp\Greater       [$1, $3]; }
631
    | expr T_IS_GREATER_OR_EQUAL expr                       { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; }
632
    | expr T_INSTANCEOF class_name_reference                { $$ = Expr\Instanceof_[$1, $3]; }
633
    | parentheses_expr                                      { $$ = $1; }
634
    /* we need a separate '(' new_expr ')' rule to avoid problems caused by a s/r conflict */
635
    | '(' new_expr ')'                                      { $$ = $2; }
636
    | expr '?' expr ':' expr                                { $$ = Expr\Ternary[$1, $3,   $5]; }
637
    | expr '?' ':' expr                                     { $$ = Expr\Ternary[$1, null, $4]; }
638
    | expr T_COALESCE expr                                  { $$ = Expr\BinaryOp\Coalesce[$1, $3]; }
639
    | T_ISSET '(' variables_list ')'                        { $$ = Expr\Isset_[$3]; }
640
    | T_EMPTY '(' expr ')'                                  { $$ = Expr\Empty_[$3]; }
641
    | T_INCLUDE expr                                        { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; }
642
    | T_INCLUDE_ONCE expr                                   { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; }
643
    | T_EVAL parentheses_expr                               { $$ = Expr\Eval_[$2]; }
644
    | T_REQUIRE expr                                        { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE]; }
645
    | T_REQUIRE_ONCE expr                                   { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE_ONCE]; }
646
    | T_INT_CAST expr                                       { $$ = Expr\Cast\Int_    [$2]; }
647
    | T_DOUBLE_CAST expr
648
          { $attrs = attributes();
649
            $attrs['kind'] = $this->getFloatCastKind($1);
650
            $$ = new Expr\Cast\Double($2, $attrs); }
651
    | T_STRING_CAST expr                                    { $$ = Expr\Cast\String_ [$2]; }
652
    | T_ARRAY_CAST expr                                     { $$ = Expr\Cast\Array_  [$2]; }
653
    | T_OBJECT_CAST expr                                    { $$ = Expr\Cast\Object_ [$2]; }
654
    | T_BOOL_CAST expr                                      { $$ = Expr\Cast\Bool_   [$2]; }
655
    | T_UNSET_CAST expr                                     { $$ = Expr\Cast\Unset_  [$2]; }
656
    | T_EXIT exit_expr
657
          { $attrs = attributes();
658
            $attrs['kind'] = strtolower($1) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE;
659
            $$ = new Expr\Exit_($2, $attrs); }
660
    | '@' expr                                              { $$ = Expr\ErrorSuppress[$2]; }
661
    | scalar                                                { $$ = $1; }
662
    | array_expr                                            { $$ = $1; }
663
    | scalar_dereference                                    { $$ = $1; }
664
    | '`' backticks_expr '`'                                { $$ = Expr\ShellExec[$2]; }
665
    | T_PRINT expr                                          { $$ = Expr\Print_[$2]; }
666
    | T_YIELD                                               { $$ = Expr\Yield_[null, null]; }
667
    | T_YIELD_FROM expr                                     { $$ = Expr\YieldFrom[$2]; }
668
    | T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
669
      '{' inner_statement_list '}'
670
          { $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $9]]; }
671
    | T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
672
      '{' inner_statement_list '}'
673
          { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $10]]; }
674
;
675
 
676
parentheses_expr:
677
      '(' expr ')'                                          { $$ = $2; }
678
    | '(' yield_expr ')'                                    { $$ = $2; }
679
;
680
 
681
yield_expr:
682
      T_YIELD expr                                          { $$ = Expr\Yield_[$2, null]; }
683
    | T_YIELD expr T_DOUBLE_ARROW expr                      { $$ = Expr\Yield_[$4, $2]; }
684
;
685
 
686
array_expr:
687
      T_ARRAY '(' array_pair_list ')'
688
          { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG;
689
            $$ = new Expr\Array_($3, $attrs); }
690
    | '[' array_pair_list ']'
691
          { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT;
692
            $$ = new Expr\Array_($2, $attrs); }
693
;
694
 
695
scalar_dereference:
696
      array_expr '[' dim_offset ']'                         { $$ = Expr\ArrayDimFetch[$1, $3]; }
697
    | T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'         { $$ = Expr\ArrayDimFetch[Scalar\String_::fromString($1, attributes()), $3]; }
698
    | constant '[' dim_offset ']'                           { $$ = Expr\ArrayDimFetch[$1, $3]; }
699
    | scalar_dereference '[' dim_offset ']'                 { $$ = Expr\ArrayDimFetch[$1, $3]; }
700
    /* alternative array syntax missing intentionally */
701
;
702
 
703
anonymous_class:
704
      T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
705
          { $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $3, 'implements' => $4, 'stmts' => $6]], $2);
706
            $this->checkClass($$[0], -1); }
707
;
708
 
709
new_expr:
710
      T_NEW class_name_reference ctor_arguments             { $$ = Expr\New_[$2, $3]; }
711
    | T_NEW anonymous_class
712
          { list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; }
713
;
714
 
715
lexical_vars:
716
      /* empty */                                           { $$ = array(); }
717
    | T_USE '(' lexical_var_list ')'                        { $$ = $3; }
718
;
719
 
720
lexical_var_list:
721
      lexical_var                                           { init($1); }
722
    | lexical_var_list ',' lexical_var                      { push($1, $3); }
723
;
724
 
725
lexical_var:
726
      optional_ref plain_variable                           { $$ = Expr\ClosureUse[$2, $1]; }
727
;
728
 
150 lars 729
name_readonly:
730
      T_READONLY                                            { $$ = Name[$1]; }
731
;
732
 
148 lars 733
function_call:
734
      name argument_list                                    { $$ = Expr\FuncCall[$1, $2]; }
150 lars 735
    | name_readonly argument_list                           { $$ = Expr\FuncCall[$1, $2]; }
148 lars 736
    | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex argument_list
737
          { $$ = Expr\StaticCall[$1, $3, $4]; }
738
    | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' argument_list
739
          { $$ = Expr\StaticCall[$1, $4, $6]; }
740
    | static_property argument_list
741
          { $$ = $this->fixupPhp5StaticPropCall($1, $2, attributes()); }
742
    | variable_without_objects argument_list
743
          { $$ = Expr\FuncCall[$1, $2]; }
744
    | function_call '[' dim_offset ']'                      { $$ = Expr\ArrayDimFetch[$1, $3]; }
745
      /* alternative array syntax missing intentionally */
746
;
747
 
748
class_name:
749
      T_STATIC                                              { $$ = Name[$1]; }
750
    | name                                                  { $$ = $1; }
751
;
752
 
753
name:
754
      T_STRING                                              { $$ = Name[$1]; }
755
    | T_NAME_QUALIFIED                                      { $$ = Name[$1]; }
756
    | T_NAME_FULLY_QUALIFIED                                { $$ = Name\FullyQualified[substr($1, 1)]; }
757
    | T_NAME_RELATIVE                                       { $$ = Name\Relative[substr($1, 10)]; }
758
;
759
 
760
class_name_reference:
761
      class_name                                            { $$ = $1; }
762
    | dynamic_class_name_reference                          { $$ = $1; }
763
;
764
 
765
dynamic_class_name_reference:
766
      object_access_for_dcnr                                { $$ = $1; }
767
    | base_variable                                         { $$ = $1; }
768
;
769
 
770
class_name_or_var:
771
      class_name                                            { $$ = $1; }
772
    | reference_variable                                    { $$ = $1; }
773
;
774
 
775
object_access_for_dcnr:
776
      base_variable T_OBJECT_OPERATOR object_property
777
          { $$ = Expr\PropertyFetch[$1, $3]; }
778
    | object_access_for_dcnr T_OBJECT_OPERATOR object_property
779
          { $$ = Expr\PropertyFetch[$1, $3]; }
780
    | object_access_for_dcnr '[' dim_offset ']'             { $$ = Expr\ArrayDimFetch[$1, $3]; }
781
    | object_access_for_dcnr '{' expr '}'                   { $$ = Expr\ArrayDimFetch[$1, $3]; }
782
;
783
 
784
exit_expr:
785
      /* empty */                                           { $$ = null; }
786
    | '(' ')'                                               { $$ = null; }
787
    | parentheses_expr                                      { $$ = $1; }
788
;
789
 
790
backticks_expr:
791
      /* empty */                                           { $$ = array(); }
792
    | T_ENCAPSED_AND_WHITESPACE
793
          { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`', false)]); }
794
    | encaps_list                                           { parseEncapsed($1, '`', false); $$ = $1; }
795
;
796
 
797
ctor_arguments:
798
      /* empty */                                           { $$ = array(); }
799
    | argument_list                                         { $$ = $1; }
800
;
801
 
802
common_scalar:
803
      T_LNUMBER                                             { $$ = $this->parseLNumber($1, attributes(), true); }
804
    | T_DNUMBER                                             { $$ = Scalar\DNumber::fromString($1, attributes()); }
805
    | T_CONSTANT_ENCAPSED_STRING                            { $$ = Scalar\String_::fromString($1, attributes(), false); }
806
    | T_LINE                                                { $$ = Scalar\MagicConst\Line[]; }
807
    | T_FILE                                                { $$ = Scalar\MagicConst\File[]; }
808
    | T_DIR                                                 { $$ = Scalar\MagicConst\Dir[]; }
809
    | T_CLASS_C                                             { $$ = Scalar\MagicConst\Class_[]; }
810
    | T_TRAIT_C                                             { $$ = Scalar\MagicConst\Trait_[]; }
811
    | T_METHOD_C                                            { $$ = Scalar\MagicConst\Method[]; }
812
    | T_FUNC_C                                              { $$ = Scalar\MagicConst\Function_[]; }
813
    | T_NS_C                                                { $$ = Scalar\MagicConst\Namespace_[]; }
814
    | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
815
          { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), false); }
816
    | T_START_HEREDOC T_END_HEREDOC
817
          { $$ = $this->parseDocString($1, '', $2, attributes(), stackAttributes(#2), false); }
818
;
819
 
820
static_scalar:
821
      common_scalar                                         { $$ = $1; }
822
    | class_name T_PAAMAYIM_NEKUDOTAYIM identifier_ex       { $$ = Expr\ClassConstFetch[$1, $3]; }
823
    | name                                                  { $$ = Expr\ConstFetch[$1]; }
824
    | T_ARRAY '(' static_array_pair_list ')'                { $$ = Expr\Array_[$3]; }
825
    | '[' static_array_pair_list ']'                        { $$ = Expr\Array_[$2]; }
826
    | static_operation                                      { $$ = $1; }
827
;
828
 
829
static_operation:
830
      static_scalar T_BOOLEAN_OR static_scalar              { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; }
831
    | static_scalar T_BOOLEAN_AND static_scalar             { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; }
832
    | static_scalar T_LOGICAL_OR static_scalar              { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; }
833
    | static_scalar T_LOGICAL_AND static_scalar             { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; }
834
    | static_scalar T_LOGICAL_XOR static_scalar             { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; }
835
    | static_scalar '|' static_scalar                       { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; }
836
    | static_scalar T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG static_scalar
837
          { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
838
    | static_scalar T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG static_scalar
839
          { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
840
    | static_scalar '^' static_scalar                       { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; }
841
    | static_scalar '.' static_scalar                       { $$ = Expr\BinaryOp\Concat    [$1, $3]; }
842
    | static_scalar '+' static_scalar                       { $$ = Expr\BinaryOp\Plus      [$1, $3]; }
843
    | static_scalar '-' static_scalar                       { $$ = Expr\BinaryOp\Minus     [$1, $3]; }
844
    | static_scalar '*' static_scalar                       { $$ = Expr\BinaryOp\Mul       [$1, $3]; }
845
    | static_scalar '/' static_scalar                       { $$ = Expr\BinaryOp\Div       [$1, $3]; }
846
    | static_scalar '%' static_scalar                       { $$ = Expr\BinaryOp\Mod       [$1, $3]; }
847
    | static_scalar T_SL static_scalar                      { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; }
848
    | static_scalar T_SR static_scalar                      { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; }
849
    | static_scalar T_POW static_scalar                     { $$ = Expr\BinaryOp\Pow       [$1, $3]; }
850
    | '+' static_scalar %prec T_INC                         { $$ = Expr\UnaryPlus [$2]; }
851
    | '-' static_scalar %prec T_INC                         { $$ = Expr\UnaryMinus[$2]; }
852
    | '!' static_scalar                                     { $$ = Expr\BooleanNot[$2]; }
853
    | '~' static_scalar                                     { $$ = Expr\BitwiseNot[$2]; }
854
    | static_scalar T_IS_IDENTICAL static_scalar            { $$ = Expr\BinaryOp\Identical     [$1, $3]; }
855
    | static_scalar T_IS_NOT_IDENTICAL static_scalar        { $$ = Expr\BinaryOp\NotIdentical  [$1, $3]; }
856
    | static_scalar T_IS_EQUAL static_scalar                { $$ = Expr\BinaryOp\Equal         [$1, $3]; }
857
    | static_scalar T_IS_NOT_EQUAL static_scalar            { $$ = Expr\BinaryOp\NotEqual      [$1, $3]; }
858
    | static_scalar '<' static_scalar                       { $$ = Expr\BinaryOp\Smaller       [$1, $3]; }
859
    | static_scalar T_IS_SMALLER_OR_EQUAL static_scalar     { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; }
860
    | static_scalar '>' static_scalar                       { $$ = Expr\BinaryOp\Greater       [$1, $3]; }
861
    | static_scalar T_IS_GREATER_OR_EQUAL static_scalar     { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; }
862
    | static_scalar '?' static_scalar ':' static_scalar     { $$ = Expr\Ternary[$1, $3,   $5]; }
863
    | static_scalar '?' ':' static_scalar                   { $$ = Expr\Ternary[$1, null, $4]; }
864
    | static_scalar '[' static_scalar ']'                   { $$ = Expr\ArrayDimFetch[$1, $3]; }
865
    | '(' static_scalar ')'                                 { $$ = $2; }
866
;
867
 
868
constant:
869
      name                                                  { $$ = Expr\ConstFetch[$1]; }
870
    | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex
871
          { $$ = Expr\ClassConstFetch[$1, $3]; }
872
;
873
 
874
scalar:
875
      common_scalar                                         { $$ = $1; }
876
    | constant                                              { $$ = $1; }
877
    | '"' encaps_list '"'
878
          { $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED;
879
            parseEncapsed($2, '"', true); $$ = new Scalar\Encapsed($2, $attrs); }
880
    | T_START_HEREDOC encaps_list T_END_HEREDOC
881
          { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), true); }
882
;
883
 
884
static_array_pair_list:
885
      /* empty */                                           { $$ = array(); }
886
    | non_empty_static_array_pair_list optional_comma       { $$ = $1; }
887
;
888
 
889
optional_comma:
890
      /* empty */
891
    | ','
892
;
893
 
894
non_empty_static_array_pair_list:
895
      non_empty_static_array_pair_list ',' static_array_pair { push($1, $3); }
896
    | static_array_pair                                      { init($1); }
897
;
898
 
899
static_array_pair:
900
      static_scalar T_DOUBLE_ARROW static_scalar            { $$ = Expr\ArrayItem[$3, $1,   false]; }
901
    | static_scalar                                         { $$ = Expr\ArrayItem[$1, null, false]; }
902
;
903
 
904
variable:
905
      object_access                                         { $$ = $1; }
906
    | base_variable                                         { $$ = $1; }
907
    | function_call                                         { $$ = $1; }
908
    | new_expr_array_deref                                  { $$ = $1; }
909
;
910
 
911
new_expr_array_deref:
912
      '(' new_expr ')' '[' dim_offset ']'                   { $$ = Expr\ArrayDimFetch[$2, $5]; }
913
    | new_expr_array_deref '[' dim_offset ']'               { $$ = Expr\ArrayDimFetch[$1, $3]; }
914
      /* alternative array syntax missing intentionally */
915
;
916
 
917
object_access:
918
      variable_or_new_expr T_OBJECT_OPERATOR object_property
919
          { $$ = Expr\PropertyFetch[$1, $3]; }
920
    | variable_or_new_expr T_OBJECT_OPERATOR object_property argument_list
921
          { $$ = Expr\MethodCall[$1, $3, $4]; }
922
    | object_access argument_list                           { $$ = Expr\FuncCall[$1, $2]; }
923
    | object_access '[' dim_offset ']'                      { $$ = Expr\ArrayDimFetch[$1, $3]; }
924
    | object_access '{' expr '}'                            { $$ = Expr\ArrayDimFetch[$1, $3]; }
925
;
926
 
927
variable_or_new_expr:
928
      variable                                              { $$ = $1; }
929
    | '(' new_expr ')'                                      { $$ = $2; }
930
;
931
 
932
variable_without_objects:
933
      reference_variable                                    { $$ = $1; }
934
    | '$' variable_without_objects                          { $$ = Expr\Variable[$2]; }
935
;
936
 
937
base_variable:
938
      variable_without_objects                              { $$ = $1; }
939
    | static_property                                       { $$ = $1; }
940
;
941
 
942
static_property:
943
      class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable
944
          { $$ = Expr\StaticPropertyFetch[$1, $4]; }
945
    | static_property_with_arrays                           { $$ = $1; }
946
;
947
 
948
static_property_simple_name:
949
      T_VARIABLE
950
          { $var = parseVar($1); $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; }
951
;
952
 
953
static_property_with_arrays:
954
      class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_property_simple_name
955
          { $$ = Expr\StaticPropertyFetch[$1, $3]; }
956
    | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
957
          { $$ = Expr\StaticPropertyFetch[$1, $5]; }
958
    | static_property_with_arrays '[' dim_offset ']'        { $$ = Expr\ArrayDimFetch[$1, $3]; }
959
    | static_property_with_arrays '{' expr '}'              { $$ = Expr\ArrayDimFetch[$1, $3]; }
960
;
961
 
962
reference_variable:
963
      reference_variable '[' dim_offset ']'                 { $$ = Expr\ArrayDimFetch[$1, $3]; }
964
    | reference_variable '{' expr '}'                       { $$ = Expr\ArrayDimFetch[$1, $3]; }
965
    | plain_variable                                        { $$ = $1; }
966
    | '$' '{' expr '}'                                      { $$ = Expr\Variable[$3]; }
967
;
968
 
969
dim_offset:
970
      /* empty */                                           { $$ = null; }
971
    | expr                                                  { $$ = $1; }
972
;
973
 
974
object_property:
975
      identifier                                            { $$ = $1; }
976
    | '{' expr '}'                                          { $$ = $2; }
977
    | variable_without_objects                              { $$ = $1; }
978
    | error                                                 { $$ = Expr\Error[]; $this->errorState = 2; }
979
;
980
 
981
list_expr:
982
      T_LIST '(' list_expr_elements ')'                     { $$ = Expr\List_[$3]; }
983
;
984
 
985
list_expr_elements:
986
      list_expr_elements ',' list_expr_element              { push($1, $3); }
987
    | list_expr_element                                     { init($1); }
988
;
989
 
990
list_expr_element:
991
      variable                                              { $$ = Expr\ArrayItem[$1, null, false]; }
992
    | list_expr                                             { $$ = Expr\ArrayItem[$1, null, false]; }
993
    | /* empty */                                           { $$ = null; }
994
;
995
 
996
array_pair_list:
997
      /* empty */                                           { $$ = array(); }
998
    | non_empty_array_pair_list optional_comma              { $$ = $1; }
999
;
1000
 
1001
non_empty_array_pair_list:
1002
      non_empty_array_pair_list ',' array_pair              { push($1, $3); }
1003
    | array_pair                                            { init($1); }
1004
;
1005
 
1006
array_pair:
1007
      expr T_DOUBLE_ARROW expr                              { $$ = Expr\ArrayItem[$3, $1,   false]; }
1008
    | expr                                                  { $$ = Expr\ArrayItem[$1, null, false]; }
1009
    | expr T_DOUBLE_ARROW ampersand variable                { $$ = Expr\ArrayItem[$4, $1,   true]; }
1010
    | ampersand variable                                    { $$ = Expr\ArrayItem[$2, null, true]; }
1011
    | T_ELLIPSIS expr                                       { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; }
1012
;
1013
 
1014
encaps_list:
1015
      encaps_list encaps_var                                { push($1, $2); }
1016
    | encaps_list encaps_string_part                        { push($1, $2); }
1017
    | encaps_var                                            { init($1); }
1018
    | encaps_string_part encaps_var                         { init($1, $2); }
1019
;
1020
 
1021
encaps_string_part:
1022
      T_ENCAPSED_AND_WHITESPACE                             { $$ = Scalar\EncapsedStringPart[$1]; }
1023
;
1024
 
1025
encaps_str_varname:
1026
      T_STRING_VARNAME                                      { $$ = Expr\Variable[$1]; }
1027
;
1028
 
1029
encaps_var:
1030
      plain_variable                                        { $$ = $1; }
1031
    | plain_variable '[' encaps_var_offset ']'              { $$ = Expr\ArrayDimFetch[$1, $3]; }
1032
    | plain_variable T_OBJECT_OPERATOR identifier           { $$ = Expr\PropertyFetch[$1, $3]; }
1033
    | T_DOLLAR_OPEN_CURLY_BRACES expr '}'                   { $$ = Expr\Variable[$2]; }
1034
    | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'       { $$ = Expr\Variable[$2]; }
1035
    | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}'
1036
          { $$ = Expr\ArrayDimFetch[$2, $4]; }
1037
    | T_CURLY_OPEN variable '}'                             { $$ = $2; }
1038
;
1039
 
1040
encaps_var_offset:
1041
      T_STRING                                              { $$ = Scalar\String_[$1]; }
1042
    | T_NUM_STRING                                          { $$ = $this->parseNumString($1, attributes()); }
1043
    | plain_variable                                        { $$ = $1; }
1044
;
1045
 
1046
%%