# Help w/ Parser

- Thread: https://externals.io/message/56083
- Original archive: https://news-web.php.net/php.internals/56083
- Started by php-dev@zerocue.com on 2011-11-07T02:53:52+00:00
- Messages: 9
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #56083 — php-dev@zerocue.com — 2011-11-07T02:53:52+00:00

URL: https://externals.io/message/56083#56083

I'm having trouble getting some changes to the parser to recognize some new
syntax.  I've attached a patch of what I've done.

 

Here is the syntax I am trying to get to be parsed properly:

<?php

class TimePeriod {

     

     public $Seconds;

 

     public function __construct($Seconds) {

           $this->Seconds = $Seconds;

     }

     // Getters/Setters

     public $Hours {

           get { return $this->Seconds / 3600; }

           set { $this->Seconds = $value * 3600; } // The variable $value
holds the incoming value to be "set"

     }

};

?>

 

After compiling and attempting to execute the above PHP file, I'm getting
this parse error:

 

Parse error: syntax error, unexpected 'get' (T_STRING), expecting get
(T_GET) or set (T_SET) in /mnt/hgfs/svn/php-src-test/test.php on line 13

 

Why is the parse recognizing the 'get' as `T_STRING` rather than get (T_GET)?

 

Thanks,

 

-Clint

---

## #56084 — Nikita Popov — 2011-11-07T06:11:33+00:00

URL: https://externals.io/message/56083#56084 · In reply to: #56083

I don't see an attachment. Could you send it again with .txt as file extension?

If you want 'get' to be recognized as T_GET you need to define such a
token in the lexer (zend_language_scanner.l). Did you do that?


> I’m having trouble getting some changes to the parser to recognize some new
> syntax.  I’ve attached a patch of what I’ve done.
>
>
>
> Here is the syntax I am trying to get to be parsed properly:
>
> <?php
>
> class TimePeriod {
>
>
>
>      public $Seconds;
>
>
>
>      public function __construct($Seconds) {
>
>            $this->Seconds = $Seconds;
>
>      }
>
>      // Getters/Setters
>
>      public $Hours {
>
>            get { return $this->Seconds / 3600; }
>
>            set { $this->Seconds = $value * 3600; } // The variable $value
> holds the incoming value to be "set"
>
>      }
>
> };
>
> ?>
>
>
>
> After compiling and attempting to execute the above PHP file, I’m getting
> this parse error:
>
>
>
> Parse error: syntax error, unexpected 'get' (T_STRING), expecting get
> (T_GET) or set (T_SET) in /mnt/hgfs/svn/php-src-test/test.php on line 13
>
>
>
> Why is the parse recognizing the ‘get’ as `T_STRING` rather than get (T_GET)?
>
>
>
> Thanks,
>
>
>
> -Clint

---

## #56087 — Keloran — 2011-11-07T09:12:01+00:00

URL: https://externals.io/message/56083#56087 · In reply to: #56084

this looks cool if you get it to work, move the object-orientation forwards
quite abit

On Mon, Nov 7, 2011 at 6:11 AM, Nikita Popov <nikita.ppv@googlemail.com>wrote:

> I don't see an attachment. Could you send it again with .txt as file
> extension?
>
> If you want 'get' to be recognized as T_GET you need to define such a
> token in the lexer (zend_language_scanner.l). Did you do that?
>
> 
> > […]
> new
> > […]
> (T_GET)?
> > […]

---

## #56093 — Hartmut Holzgraefe — 2011-11-07T11:31:30+00:00

URL: https://externals.io/message/56083#56093 · In reply to: #56087

> this looks cool if you get it to work

+1 want have! :)

-- 
hartmut

---

## #56094 — Hannes Magnusson — 2011-11-07T14:03:44+00:00

URL: https://externals.io/message/56083#56094 · In reply to: #56093

On Mon, Nov 7, 2011 at 12:31, Hartmut Holzgraefe
<hartmut.holzgraefe@gmail.com> wrote:
> 
> > […]
>
> +1 want have! :)

Same here.
As long as someone doesn't think this creates precedence for importing
C# features and thinks implementing partial classes will be cool :)

Btw; https://wiki.php.net/rfc/propertygetsetsyntax

..and only text/plain attachments come through.

-Hannes

---

## #56101 — Clint M Priest — 2011-11-07T15:54:51+00:00

URL: https://externals.io/message/56083#56101 · In reply to: #56094

I didn't change the zend_language_scanner.l, attached is the (.txt) diff that I had at the original time of writing, I'll give that a try.

I am planning to go by the RFC mentioned below, I've already been emailing with that original author who tells me most of the feedback he received during its initial inception has been integrated into the RFC.  

Does anyone have any feedback about that RFC as it is now?  The one thing I would like to see different about how it works vs c# is that if $Seconds were defined as a getter/setter, $this->Seconds from within the getter/setter would access the data storage, rather than the getter/setter function so that one does not have to defined an additional datastore for each and every getter/setter.

-----Original Message-----
From: Hannes Magnusson [mailto:hannes.magnusson@gmail.com] 
Sent: Monday, November 07, 2011 8:04 AM
To: Hartmut Holzgraefe; php-dev@zerocue.com
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Help w/ Parser


> 
> > […]
>
> +1 want have! :)

Same here.
As long as someone doesn't think this creates precedence for importing C# features and thinks implementing partial classes will be cool :)

Btw; https://wiki.php.net/rfc/propertygetsetsyntax

..and only text/plain attachments come through.

-Hannes

---

## #56105 — irker@irker.net — 2011-11-07T16:21:23+00:00

URL: https://externals.io/message/56083#56105 · In reply to: #56083

What about expressions between { } in  getter_setter_declaration ?
In your example we see  "set {something}" and not "set {}" as you declared.

Sorry if I wrong. I'm not C coder =)

With regards, Alexander Moskaliov
Irker@irker.net


2011/11/7 <php-dev@zerocue.com>

> I’m having trouble getting some changes to the parser to recognize some
> new syntax.  I’ve attached a patch of what I’ve done.****
>
> ** **
>
> Here is the syntax I am trying to get to be parsed properly:****
>
> <?php****
>
> class TimePeriod {****
>
>      ****
>
>      public $Seconds;****
>
> ** **
>
>      public function __construct($Seconds) {****
>
>            $this->Seconds = $Seconds;****
>
>      }****
>
> ****
>
>      // Getters/Setters****
>
>      public $Hours {****
>
>            get { return $this->Seconds / 3600; }****
>
>            set { $this->Seconds = $value * 3600; } // The variable $value
> holds the incoming value to be "set"****
>
>      }****
>
> };****
>
> ?>****
>
> ** **
>
> After compiling and attempting to execute the above PHP file, I’m getting
> this parse error:****
>
> ** **
>
> Parse error: syntax error, unexpected 'get' (T_STRING), expecting get
> (T_GET) or set (T_SET) in /mnt/hgfs/svn/php-src-test/test.php on line 13**
> **
>
> ** **
>
> Why is the parse recognizing the ‘get’ as `T_STRING` rather than get (T_GET)?
> ****
>
> ** **
>
> Thanks,****
>
> ** **
>
> -Clint****

---

## #56109 — Clint M Priest — 2011-11-07T16:58:18+00:00

URL: https://externals.io/message/56083#56109 · In reply to: #56084

I'm sure the problem is that I hadn't modified the .l file as Nikita suggested, which I have now done but the build doesn't seem to be affected by changes to that file so I'm trying to find out how to make that occur.  I believe it's via re2c which I have installed but a make clean/make still results in the same error.

Is there something I need to run to process zend_language_scanner.l?

-----Original Message-----
From: Nikita Popov [mailto:nikita.ppv@googlemail.com] 
Sent: Monday, November 07, 2011 12:12 AM
To: php-dev@zerocue.com
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Help w/ Parser

I don't see an attachment. Could you send it again with .txt as file extension?

If you want 'get' to be recognized as T_GET you need to define such a token in the lexer (zend_language_scanner.l). Did you do that?


> I'm having trouble getting some changes to the parser to recognize 
> some new syntax.  I've attached a patch of what I've done.
>
>
>
> Here is the syntax I am trying to get to be parsed properly:
>
> <?php
>
> class TimePeriod {
>
>
>
>      public $Seconds;
>
>
>
>      public function __construct($Seconds) {
>
>            $this->Seconds = $Seconds;
>
>      }
>
>      // Getters/Setters
>
>      public $Hours {
>
>            get { return $this->Seconds / 3600; }
>
>            set { $this->Seconds = $value * 3600; } // The variable 
> $value holds the incoming value to be "set"
>
>      }
>
> };
>
> ?>
>
>
>
> After compiling and attempting to execute the above PHP file, I'm 
> getting this parse error:
>
>
>
> Parse error: syntax error, unexpected 'get' (T_STRING), expecting get
> (T_GET) or set (T_SET) in /mnt/hgfs/svn/php-src-test/test.php on line 
> 13
>
>
>
> Why is the parse recognizing the 'get' as `T_STRING` rather than get (T_GET)?
>
>
>
> Thanks,
>
>
>
> -Clint
>
> --
>  To unsubscribe, 
> visit: http://www.php.net/unsub.php

---

## #56113 — johannes@schlueters.de — 2011-11-07T17:30:50+00:00

URL: https://externals.io/message/56083#56113 · In reply to: #56109

> I'm sure the problem is that I hadn't modified the .l file as Nikita
> suggested, which I have now done but the build doesn't seem to be
> affected by changes to that file so I'm trying to find out how to make
> that occur.  I believe it's via re2c which I have installed but a make
> clean/make still results in the same error.
> 
> Is there something I need to run to process zend_language_scanner.l?

After installing re2c re-run configure. check the configure output for
re2c references. We don't expect Average Joe to have it installed and
fail silently if it's not detected. You can also delete
zend_language_scanner.c.

johannes

> -----Original Message-----
> From: Nikita Popov [mailto:nikita.ppv@googlemail.com] 
> Sent: Monday, November 07, 2011 12:12 AM
> To: php-dev@zerocue.com
> Cc: internals@lists.php.net
> Subject: Re: [PHP-DEV] Help w/ Parser
> 
> I don't see an attachment. Could you send it again with .txt as file extension?
> 
> If you want 'get' to be recognized as T_GET you need to define such a token in the lexer (zend_language_scanner.l). Did you do that?
> 
> 
> > […]
