Skip to content

Commit c6a5c3c

Browse files
committed
Remove parenthesis_expr
This was necessary previously to handle yields, now it only clutters up the grammar.
1 parent 7722d2c commit c6a5c3c

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

Zend/zend_language_parser.y

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
227227

228228
%type <ast> top_statement namespace_name name statement function_declaration_statement
229229
%type <ast> class_declaration_statement use_declaration const_decl inner_statement
230-
%type <ast> parenthesis_expr expr while_statement for_statement foreach_variable
230+
%type <ast> expr while_statement for_statement foreach_variable
231231
%type <ast> foreach_statement declare_statement finally_statement unset_variable variable
232232
%type <ast> extends_from parameter optional_type argument expr_without_variable global_var
233233
%type <ast> static_var class_statement trait_adaptation trait_precedence trait_alias
@@ -351,14 +351,14 @@ statement:
351351
'{' inner_statement_list '}' { $$ = $<ast>2; }
352352
| if_stmt { $$ = $<ast>1; }
353353
| alt_if_stmt { $$ = $<ast>1; }
354-
| T_WHILE parenthesis_expr while_statement
355-
{ $$ = zend_ast_create(ZEND_AST_WHILE, $2, $3); }
356-
| T_DO statement T_WHILE parenthesis_expr ';'
357-
{ $$ = zend_ast_create(ZEND_AST_DO_WHILE, $2, $4); }
354+
| T_WHILE '(' expr ')' while_statement
355+
{ $$ = zend_ast_create(ZEND_AST_WHILE, $3, $5); }
356+
| T_DO statement T_WHILE '(' expr ')' ';'
357+
{ $$ = zend_ast_create(ZEND_AST_DO_WHILE, $2, $5); }
358358
| T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement
359359
{ $$ = zend_ast_create(ZEND_AST_FOR, $<ast>3, $<ast>5, $<ast>7, $9); }
360-
| T_SWITCH parenthesis_expr switch_case_list
361-
{ $$ = zend_ast_create(ZEND_AST_SWITCH, $2, $<ast>3); }
360+
| T_SWITCH '(' expr ')' switch_case_list
361+
{ $$ = zend_ast_create(ZEND_AST_SWITCH, $3, $<ast>5); }
362362
| T_BREAK ';' { $$ = zend_ast_create(ZEND_AST_BREAK, NULL); }
363363
| T_BREAK expr ';' { $$ = zend_ast_create(ZEND_AST_BREAK, $2); }
364364
| T_CONTINUE ';' { $$ = zend_ast_create(ZEND_AST_CONTINUE, NULL); }
@@ -508,12 +508,12 @@ while_statement:
508508

509509

510510
if_stmt_without_else:
511-
T_IF parenthesis_expr statement
511+
T_IF '(' expr ')' statement
512512
{ $$ = zend_ast_create_list(1, ZEND_AST_IF,
513-
zend_ast_create(ZEND_AST_IF_ELEM, $2, $3)); }
514-
| if_stmt_without_else T_ELSEIF parenthesis_expr statement
513+
zend_ast_create(ZEND_AST_IF_ELEM, $3, $5)); }
514+
| if_stmt_without_else T_ELSEIF '(' expr ')' statement
515515
{ $$ = zend_ast_list_add($1,
516-
zend_ast_create(ZEND_AST_IF_ELEM, $3, $4)); }
516+
zend_ast_create(ZEND_AST_IF_ELEM, $4, $6)); }
517517
;
518518

519519
if_stmt:
@@ -523,12 +523,12 @@ if_stmt:
523523
;
524524

525525
alt_if_stmt_without_else:
526-
T_IF parenthesis_expr ':' inner_statement_list
526+
T_IF '(' expr ')' ':' inner_statement_list
527527
{ $$ = zend_ast_create_list(1, ZEND_AST_IF,
528-
zend_ast_create(ZEND_AST_IF_ELEM, $2, $<ast>4)); }
529-
| alt_if_stmt_without_else T_ELSEIF parenthesis_expr ':' inner_statement_list
528+
zend_ast_create(ZEND_AST_IF_ELEM, $3, $<ast>6)); }
529+
| alt_if_stmt_without_else T_ELSEIF '(' expr ')' ':' inner_statement_list
530530
{ $$ = zend_ast_list_add($1,
531-
zend_ast_create(ZEND_AST_IF_ELEM, $3, $<ast>5)); }
531+
zend_ast_create(ZEND_AST_IF_ELEM, $4, $<ast>7)); }
532532
;
533533

534534
alt_if_stmt:
@@ -833,7 +833,7 @@ expr_without_variable:
833833
{ $$ = zend_ast_create(ZEND_AST_GREATER_EQUAL, $1, $3); }
834834
| expr T_INSTANCEOF class_name_reference
835835
{ $$ = zend_ast_create(ZEND_AST_INSTANCEOF, $1, $3); }
836-
| parenthesis_expr { $$ = $1; }
836+
| '(' expr ')' { $$ = $2; }
837837
| new_expr { $$ = $1; }
838838
| expr '?' expr ':' expr
839839
{ $$ = zend_ast_create(ZEND_AST_CONDITIONAL, $1, $3, $5); }
@@ -929,9 +929,9 @@ class_name_reference:
929929
;
930930

931931
exit_expr:
932-
/* empty */ { $$ = NULL; }
933-
| '(' ')' { $$ = NULL; }
934-
| parenthesis_expr { $$ = $1; }
932+
/* empty */ { $$ = NULL; }
933+
| '(' ')' { $$ = NULL; }
934+
| '(' expr ')' { $$ = $2; }
935935
;
936936

937937
backticks_expr:
@@ -993,10 +993,6 @@ expr:
993993
| expr_without_variable { $$ = $1; }
994994
;
995995

996-
parenthesis_expr:
997-
'(' expr ')' { $$ = $2; }
998-
;
999-
1000996
variable_class_name:
1001997
dereferencable { $$ = $1; }
1002998
;

0 commit comments

Comments
 (0)