I would like to extend the php syntax, in order to tell apart mutable and immutable variables.
$a should be declared mutable (as in standard php)
and #b should be declared immutable.
I've read Hacking PHP syntax,
and I couldn't figure out where can I define that variables declared with # should also be tokenized as T_VARIABLE ?
I was able to solve this issue, Two steps need to be taken:
PHP not parse '#' as comments:Change:
<ST_IN_SCRIPTING>"#"|"//" {
To
<ST_IN_SCRIPTING>"//" {
In line 1901 in zend_language_scanner.l
#a as a variable:Change:
simple_variable:
T_VARIABLE { $$ = $1; }
| '$' '{' expr '}' { $$ = $3; }
| '$' simple_variable { $$ = zend_ast_create(ZEND_AST_VAR, $2); }
;
To:
simple_variable:
T_VARIABLE { $$ = $1; }
| '$' '{' expr '}' { $$ = $3; }
| '$' simple_variable { $$ = zend_ast_create(ZEND_AST_VAR, $2); }
| '#' '{' expr '}' { $$ = $3; }
| '#' simple_variable { $$ = zend_ast_create(ZEND_AST_VAR, $2); }
;
In line 1117 of zend_language_parser.y
Now this code works:
#a=1;
echo (#a);//1
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With