Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28336 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11740 invoked by uid 1010); 14 Mar 2007 11:12:26 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 11725 invoked from network); 14 Mar 2007 11:12:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Mar 2007 11:12:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=php_lists@realplain.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php_lists@realplain.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain realplain.com from 69.179.208.43 cause and error) X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 69.179.208.43 msa3-mx.centurytel.net Linux 2.4/2.6 Received: from [69.179.208.43] ([69.179.208.43:45157] helo=msa3-mx.centurytel.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 01/35-02483-798D7F54 for ; Wed, 14 Mar 2007 06:12:26 -0500 Received: from pc1 (d6-4.rt-bras.wnvl.centurytel.net [69.179.133.4]) by msa3-mx.centurytel.net (8.13.6/8.13.6) with SMTP id l2EBCKa6013082 for ; Wed, 14 Mar 2007 05:12:20 -0600 Message-ID: <008801c76629$a32ce830$0201a8c0@pc1> To: Date: Wed, 14 Mar 2007 06:12:21 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1896 Subject: Optimize parsing of negative numbers? From: php_lists@realplain.com ("Matt Wilmas") Hi all, I realized awhile ago that PHP creates a ZEND_SUB opcode even with a literal number after the '-' (-123), which of course causes the number to be negated each time it's used during runtime. So a few months ago, and again recently, I took a look at the parser grammar to see if I could get these "common_scalar"/numbers to be negated once in parse/compile stage (like "static_scalar") but didn't really get anywhere. :-/ Just "reduce/reduce conflicts" even if the rules seem like they should work (but I have no idea about this Bison stuff!). Well, there was one way I eliminated the conflicts, but it seems kinda sloppy and no idea if it would actually work. For the Bison gurus, is there a simple way this could be done with a little grammar rearranging? Of course there would be a runtime improvement with negative numbers, but it should also compile faster, skipping opcode creation, etc. BTW, for "expr_without_variable", '+' expr generates ZEND_ADD. As far as I know there's no point to that, right? ;-) Its action should simply be $$ = $2; Thanks, Matt P.S. Here on Windows, I wouldn't be able to test any parser changes anyway -- Bison is somehow creating wrong files or such since if it's run with a default zend_language_parser.y, I then get "unexpected ..." parse errors that are obviously bogus. Any ideas?