Welcome! Log In Create A New Profile

Advanced

[PHP-DEV] Trouble with zend_language_parser.y

Posted by Clint Priest 
Clint Priest
[PHP-DEV] Trouble with zend_language_parser.y
April 26, 2012 05:50AM
I'm having some trouble setting up the re2c to allow the isset/unset. Here are the definitions, I've added the two T_ISSET statements:

------------------------------------------------------------
accessors:
accessor_function
accessor_function
accessor_function
accessor_function
| accessor_function
accessor_function
accessor_function
| accessor_function
accessor_function
| accessor_function
| /* Empty */
;

accessor_modifiers:
/* empty */ { Z_LVAL($$.u.constant) = CG(access_type); }
| non_empty_accessor_modifiers { $$ = $1; }
;

non_empty_accessor_modifiers:
accessor_modifier { $$ = $1; }
| non_empty_accessor_modifiers accessor_modifier { Z_LVAL($$.u.constant) = zend_do_verify_access_types(&$1, &$2); }


accessor_modifier:
T_PUBLIC { Z_LVAL($$.u.constant) = ZEND_ACC_PUBLIC; }
| T_PROTECTED { Z_LVAL($$.u.constant) = ZEND_ACC_PROTECTED; }
| T_PRIVATE { Z_LVAL($$.u.constant) = ZEND_ACC_PRIVATE; }
| T_STATIC { Z_LVAL($$.u.constant) = ZEND_ACC_STATIC; }
| T_FINAL { Z_LVAL($$.u.constant) = ZEND_ACC_FINAL; }
;

accessor_function:
T_ISSET
{ Z_LVAL($$.u.constant) = ZEND_ACC_PUBLIC; zend_do_begin_accessor_declaration(&$1, CG(accessor_node), &$$, 0 TSRMLS_CC); }
'{' inner_statement_list '}'
{ zend_do_end_accessor_declaration(&$1, CG(accessor_node), &$$, &$3 TSRMLS_CC); }
| T_ISSET
{ Z_LVAL($$.u.constant) = ZEND_ACC_PUBLIC;
zend_do_begin_accessor_declaration(&$1, CG(accessor_node), &$$, 0 TSRMLS_CC);
zend_do_end_accessor_declaration(&$1, CG(accessor_node), &$$, NULL TSRMLS_CC);
}
';'
| accessor_modifiers is_reference T_STRING
{ zend_do_begin_accessor_declaration(&$3, CG(accessor_node), &$1, $2.op_type TSRMLS_CC); }
'{' inner_statement_list '}'
{ zend_do_end_accessor_declaration(&$3, CG(accessor_node), &$1, &$5 TSRMLS_CC); }
| accessor_modifiers is_reference T_STRING
{
zend_do_begin_accessor_declaration(&$3, CG(accessor_node), &$1, $2.op_type TSRMLS_CC);
zend_do_end_accessor_declaration(&$3, CG(accessor_node), &$1, NULL TSRMLS_CC);
}
';'
;------------------------------------------------------------

Here is the PHP it's trying to parse:

public $Hours {
get {
echo "Getting Hours\r\n";
return $this->Seconds / 3600;
}
set { // The variable $value holds the incoming value to be "set"
echo "Setting Hours to {$value}\r\n";
$this->Seconds = $value * 3600;
}
isset { return $this->Seconds != NULL; }
unset { $this->Seconds = NULL; }
}

$1 of the first T_ISSET is matching against "\n\t\tisset {..." (... being the rest of the set body through to the end of the script.

What's going on here?
Clint Priest
[PHP-DEV] RE: Trouble with zend_language_parser.y
May 02, 2012 03:30PM
Anyone have any help with this?

$1 of the first T_ISSET is matching against "\n\t\tisset {..." (... being the rest of the set body through to the end of the script.

-----Original Message-----
From: Clint Priest [mailto:[email protected]]
Sent: Wednesday, April 25, 2012 10:41 PM
To: internals@lists.php.net
Subject: [PHP-DEV] Trouble with zend_language_parser.y

I'm having some trouble setting up the re2c to allow the isset/unset. Here are the definitions, I've added the two T_ISSET statements:

------------------------------------------------------------
accessors:
accessor_function
accessor_function
accessor_function
accessor_function
| accessor_function
accessor_function
accessor_function
| accessor_function
accessor_function
| accessor_function
| /* Empty */
;

accessor_modifiers:
/* empty */ { Z_LVAL($$.u.constant) = CG(access_type); }
| non_empty_accessor_modifiers { $$ = $1; }
;

non_empty_accessor_modifiers:
accessor_modifier { $$ = $1; }
| non_empty_accessor_modifiers accessor_modifier { Z_LVAL($$.u.constant) = zend_do_verify_access_types(&$1, &$2); }


accessor_modifier:
T_PUBLIC { Z_LVAL($$.u.constant) = ZEND_ACC_PUBLIC; }
| T_PROTECTED { Z_LVAL($$.u.constant) = ZEND_ACC_PROTECTED; }
| T_PRIVATE { Z_LVAL($$.u.constant) = ZEND_ACC_PRIVATE; }
| T_STATIC { Z_LVAL($$.u.constant) = ZEND_ACC_STATIC; }
| T_FINAL { Z_LVAL($$.u.constant) = ZEND_ACC_FINAL; }
;

accessor_function:
T_ISSET
{ Z_LVAL($$.u.constant) = ZEND_ACC_PUBLIC; zend_do_begin_accessor_declaration(&$1, CG(accessor_node), &$$, 0 TSRMLS_CC); }
'{' inner_statement_list '}'
{ zend_do_end_accessor_declaration(&$1, CG(accessor_node), &$$, &$3 TSRMLS_CC); }
| T_ISSET
{ Z_LVAL($$.u.constant) = ZEND_ACC_PUBLIC;
zend_do_begin_accessor_declaration(&$1, CG(accessor_node), &$$, 0 TSRMLS_CC);
zend_do_end_accessor_declaration(&$1, CG(accessor_node), &$$, NULL TSRMLS_CC);
}
';'
| accessor_modifiers is_reference T_STRING
{ zend_do_begin_accessor_declaration(&$3, CG(accessor_node), &$1, $2.op_type TSRMLS_CC); }
'{' inner_statement_list '}'
{ zend_do_end_accessor_declaration(&$3, CG(accessor_node), &$1, &$5 TSRMLS_CC); }
| accessor_modifiers is_reference T_STRING
{
zend_do_begin_accessor_declaration(&$3, CG(accessor_node), &$1, $2.op_type TSRMLS_CC);
zend_do_end_accessor_declaration(&$3, CG(accessor_node), &$1, NULL TSRMLS_CC);
}
';'
;------------------------------------------------------------

Here is the PHP it's trying to parse:

public $Hours {
get {
echo "Getting Hours\r\n";
return $this->Seconds / 3600;
}
set { // The variable $value holds the incoming value to be "set"
echo "Setting Hours to {$value}\r\n";
$this->Seconds = $value * 3600;
}
isset { return $this->Seconds != NULL; }
unset { $this->Seconds = NULL; }
}

$1 of the first T_ISSET is matching against "\n\t\tisset {..." (... being the rest of the set body through to the end of the script.

What's going on here?

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Etienne Kneuss
Re: [PHP-DEV] RE: Trouble with zend_language_parser.y
May 05, 2012 05:10PM
Hi Clint,

On Wed, May 2, 2012 at 3:23 PM, Clint Priest <[email protected]> wrote:
> Anyone have any help with this?

hard to say like this with this partial patch, do you have some git
branch I can pull from to reproduce and analyze this?
Alternatively, the complete an up-to-date patch?

Best Regards,

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Felipe Pena
Re: [PHP-DEV] Trouble with zend_language_parser.y
May 05, 2012 05:20PM
Hi,

2012/4/26 Clint Priest <[email protected]>:
> I'm having some trouble setting up the re2c to allow the isset/unset.  Here are the definitions, I've added the two T_ISSET statements:
>
> ------------------------------------------------------------
> accessors:
>                                accessor_function
>                                accessor_function
>                                accessor_function
>                                accessor_function
>                |              accessor_function
>                                accessor_function
>                                accessor_function
>                |              accessor_function
>                                accessor_function
>                |              accessor_function
>                | /* Empty */
> ;
>

This rule is weird too, do you want a limited number of accessor?

--
Regards,
Felipe Pena
Clint Priest
RE: [PHP-DEV] Trouble with zend_language_parser.y
May 07, 2012 03:50PM
This has been changed to the more traditional way.

I've moved on and am using _isset and _unset for the moment, but I'll clone my branch with what I need to accomplish and post it here tonight.

-----Original Message-----
From: Felipe Pena [mailto:[email protected]]
Sent: Saturday, May 05, 2012 10:19 AM
To: Clint Priest
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Trouble with zend_language_parser.y

Hi,

2012/4/26 Clint Priest <[email protected]>:
> I'm having some trouble setting up the re2c to allow the isset/unset.  Here are the definitions, I've added the two T_ISSET statements:
>
> ------------------------------------------------------------
> accessors:
>                                accessor_function
>                                accessor_function
>                                accessor_function
>                                accessor_function
>                |              accessor_function
>                                accessor_function
>                                accessor_function
>                |              accessor_function
>                                accessor_function
>                |              accessor_function
>                | /* Empty */
> ;
>

This rule is weird too, do you want a limited number of accessor?

--
Regards,
Felipe Pena
Clint Priest
RE: [PHP-DEV] RE: Trouble with zend_language_parser.y
May 07, 2012 09:20PM
Alright, I'm new to git but I believe I have a branch off my fork which demonstrates the issue.

https://github.com/cpriest/php-src/tree/isset-unset-issue

This branch also features just code necessary to produce the results, if you search in zend_compile.h for ISSUE-ISSET-LANGUAGE-PARSER you'll see further contextual notes on what I'm seeing that's the issue.

It seems the function_token is getting the rest of the script stuffed into it.

> -----Original Message-----
> From: ekneuss@gmail.com [mailto:[email protected]] On Behalf Of Etienne Kneuss
> Sent: Saturday, May 05, 2012 10:07 AM
> To: Clint Priest
> Cc: internals@lists.php.net
> Subject: Re: [PHP-DEV] RE: Trouble with zend_language_parser.y
>
> Hi Clint,
>
> On Wed, May 2, 2012 at 3:23 PM, Clint Priest <[email protected]> wrote:
> > Anyone have any help with this?
>
> hard to say like this with this partial patch, do you have some git branch I can pull from to reproduce and analyze this?
> Alternatively, the complete an up-to-date patch?
>
> Best Regards,
Nikita Popov
Re: [PHP-DEV] RE: Trouble with zend_language_parser.y
May 07, 2012 09:30PM
On Mon, May 7, 2012 at 9:16 PM, Clint Priest <[email protected]> wrote:
> Alright, I'm new to git but I believe I have a branch off my fork which demonstrates the issue.
>
> https://github.com/cpriest/php-src/tree/isset-unset-issue
>
> This branch also features just code necessary to produce the results, if you search in zend_compile.h for ISSUE-ISSET-LANGUAGE-PARSER you'll see further contextual notes on what I'm seeing that's the issue.
>
> It seems the function_token is getting the rest of the script stuffed into it.
When you write $1 (where 1 references a terminal) you are accessing
the zendlval of the token. Not all tokens define an lval. Only tokens
which have a meaningful value (like numbers, strings, etc). So when
accessing the value of T_ISSET you just get some junk (as it does not
set a value).

Not sure that's really right, but that would be my guess :)

Nikita

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Clint Priest
RE: [PHP-DEV] RE: Trouble with zend_language_parser.y
May 08, 2012 01:10AM
That makes complete sense, it is indeed a LONG type that's getting to that point, thank you!


> -----Original Message-----
> From: Nikita Popov [mailto:[email protected]]
> Sent: Monday, May 07, 2012 2:27 PM
> To: Clint Priest
> Cc: Etienne Kneuss; Felipe Pena ([email protected]); internals@lists.php.net
> Subject: Re: [PHP-DEV] RE: Trouble with zend_language_parser.y
>
> On Mon, May 7, 2012 at 9:16 PM, Clint Priest <[email protected]> wrote:
> > Alright, I'm new to git but I believe I have a branch off my fork which demonstrates the issue.
> >
> > https://github.com/cpriest/php-src/tree/isset-unset-issue
> >
> > This branch also features just code necessary to produce the results, if you search in zend_compile.h for ISSUE-ISSET-LANGUAGE-
> PARSER you'll see further contextual notes on what I'm seeing that's the issue.
> >
> > It seems the function_token is getting the rest of the script stuffed into it.
> When you write $1 (where 1 references a terminal) you are accessing the zendlval of the token. Not all tokens define an lval. Only
> tokens which have a meaningful value (like numbers, strings, etc). So when accessing the value of T_ISSET you just get some junk (as
> it does not set a value).
>
> Not sure that's really right, but that would be my guess :)
>
> Nikita

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login