Closed chx closed 1 week ago
Two reasons mainly: It would require duplicating parts of the grammar, given that expressions are recursive, and handling it this way allows us to provide better error messages. I'm not sure the resulting grammar would be cleaner.
I thought it would just require splitting some definitions and moving parts into new declarations but I do not readily see what would get duplicated.
How? For example:
expr:
...
| expr '+' expr { ... }
;
How do you separate this into expressions and constant expressions? The following does not work:
const_expr:
...
| const_expr '+' const_expr { ... }
;
expr:
const_expr {}
| ...
;
because then the lhs/rhs of +
cannot contain other expr
s, only const_expr
s. Which means you'll need to duplicate all productions.
Thanks, I guess then it's not possible :(
Description
I was looking at
zend_language_parser.y
and I was surprised to seeattribute
allows a fullexpr
and there's noconst_expr
definition. When I look atzend_is_allowed_in_const_expr
on the other hand, it only contains multiple comparisons to constants defined in the_zend_ast_kind
enum. In turn, it seems to me these are created inzend_language_parser.y
using calls likezend_ast_create(ZEND_AST_CLASS_CONST, $1, $4);
That means it should be possible to simply take all the declarations which lead to such anzend_ast_create()
calls for every constant inzend_is_allowed_in_const_expr
and thus define aconst_expr
in the language parser instead of deciding whether an expression is constant at compile time.Mind you I never worked with yacc before so I might be totally wrong here, I am just reading the source code. But if my observation is correct... why there isn't a
const_expr
? Should I make an attempt in creating one :) ? Is there tooling which would help creating one such?PHP Version
PHP 8.3.8
Operating System
No response