Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103325 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87229 invoked from network); 17 Oct 2018 15:46:07 -0000 Received: from unknown (HELO mail.gna.ch) (62.12.172.119) by pb1.pair.com with SMTP; 17 Oct 2018 15:46:07 -0000 Received: from [IPv6:2001:918:ff83:101:b4a4:45c5:f2a8:7c9d] (unknown [IPv6:2001:918:ff83:101:b4a4:45c5:f2a8:7c9d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id AE63020CBE for ; Wed, 17 Oct 2018 13:59:28 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Message-ID: <854A88D1-3F16-444C-A469-0DE3B89DC145@cschneid.com> Date: Wed, 17 Oct 2018 13:59:28 +0200 To: PHP internals X-Mailer: Apple Mail (2.3445.9.1) Subject: Multiple use of ast node in parser From: cschneid@cschneid.com (Christian Schneider) I'm playing around with some syntactic sugar for PHP and when trying to = implement :$foo as equivalent for 'foo' =3D> $foo I ran into the problem of having only having one ast node but trying to = use it twice. My first attempt was | ':' T_VARIABLE { $$ =3D zend_ast_create(ZEND_AST_ARRAY_ELEM, = zend_ast_create(ZEND_AST_VAR, $2), $2); } but that results in corrupted memory because of the double usage. Trying something like | ':' T_VARIABLE { $$ =3D zend_ast_create(ZEND_AST_ARRAY_ELEM, = zend_ast_create(ZEND_AST_VAR, GC_AST(zend_ast_copy($2))), $2); } works but leaks memory because the copied ast is not freed. Is there a proper way to do something like this ast transformation = inside the parser? Regards, - Chris