From: Andi Gutmans Date: Sat, 29 Jan 2000 10:16:04 +0000 (+0000) Subject: - Add parser support for string offsets. This added three shift/reduce X-Git-Tag: BEFORE_SAPIFICATION_FEB_10_2000~158 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7663e4f65ee7936047ec75e940e839caca871a86;p=php - Add parser support for string offsets. This added three shift/reduce conflicts but they all seem to be fine. - Cleaned up the parsing rules a bit and made them much more compact and elegant. - Please CVS update and see that I didn't break anything. --- diff --git a/Zend/zend-parser.y b/Zend/zend-parser.y index 64427152e0..e35a0c6cf7 100644 --- a/Zend/zend-parser.y +++ b/Zend/zend-parser.y @@ -590,8 +590,9 @@ cvar_without_objects: reference_variable: - dim_list { $$ = $1; } - | compound_variable { do_fetch_globals(&$1 CLS_CC); do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$1, 1 CLS_CC); } + reference_variable '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 CLS_CC); } + | reference_variable '{' expr '}' { fetch_string_offset(&$$, &$1, &$3 CLS_CC); } + | compound_variable { do_fetch_globals(&$1 CLS_CC); do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$1, 1 CLS_CC); } ; @@ -600,40 +601,30 @@ compound_variable: | '$' '{' expr '}' { $$ = $3; } ; - -dim_list: - dim_list '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 CLS_CC); } - | compound_variable { do_fetch_globals(&$1 CLS_CC); do_begin_variable_parse(CLS_C); } '[' dim_offset ']' { fetch_array_begin(&$$, &$1, &$4 CLS_CC); } -; - - dim_offset: /* empty */ { $$.op_type = IS_UNUSED; } | expr { $$ = $1; } ; - ref_list: object_property { $$ = $1; } | ref_list T_OBJECT_OPERATOR { do_push_object(&$1 CLS_CC); } object_property { $$ = $4; } ; object_property: - scalar_object_property { znode tmp_znode; do_pop_object(&tmp_znode CLS_CC); do_fetch_property(&$$, &tmp_znode, &$1 CLS_CC); } - | object_dim_list { $$ = $1; } -; - -scalar_object_property: - variable_name { $$ = $1; } + object_dim_list { $$ = $1; } | cvar_without_objects { do_end_variable_parse(BP_VAR_R, 0 CLS_CC); $$ = $1; } ; - object_dim_list: - object_dim_list '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 CLS_CC); } - | variable_name { znode tmp_znode, res; do_pop_object(&tmp_znode CLS_CC); do_fetch_property(&res, &tmp_znode, &$1 CLS_CC); $1 = res; } '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$4 CLS_CC); } + object_dim_list '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 CLS_CC); } + | object_dim_list '{' expr '}' { fetch_string_offset(&$$, &$1, &$3 CLS_CC); } + | property_name { $$ = $1; } ; +property_name: + variable_name { znode tmp_znode; do_pop_object(&tmp_znode CLS_CC); do_fetch_property(&$$, &tmp_znode, &$1 CLS_CC);} +; variable_name: T_STRING { $$ = $1; } diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 8a77e7bda7..9f583761d8 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -279,6 +279,11 @@ void fetch_array_dim(znode *result, znode *parent, znode *dim CLS_DC) } +void fetch_string_offset(znode *result, znode *parent, znode *offset CLS_DC) +{ +} + + void do_print(znode *result, znode *arg CLS_DC) { zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 9e331aac31..bfa61f3dd3 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -230,6 +230,7 @@ void do_fetch_globals(znode *varname CLS_DC); void fetch_array_begin(znode *result, znode *varname, znode *first_dim CLS_DC); void fetch_array_dim(znode *result, znode *parent, znode *dim CLS_DC); +void fetch_string_offset(znode *result, znode *parent, znode *offset CLS_DC); void do_print(znode *result, znode *arg CLS_DC); void do_echo(znode *arg CLS_DC); typedef int (*unary_op_type)(zval *, zval *);