Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59309 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51371 invoked from network); 1 Apr 2012 20:28:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2012 20:28:45 -0000 X-Host-Fingerprint: 217.114.211.68 unknown Date: Sun, 01 Apr 2012 16:28:44 -0400 Received: from [217.114.211.68] ([217.114.211.68:18969] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 54/97-01129-C7AB87F4 for ; Sun, 01 Apr 2012 16:28:44 -0400 To: internals@lists.php.net References: <4F7847CA.2090307@anderiasch.de> User-Agent: slrn/0.9.9p1 (SunOS) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: X-Posted-By: 217.114.211.68 Subject: Re: Question about parser implementation details From: dsp@php.net (David Soria Parra) On 2012-04-01, Florian Anderiasch wrote: > Hey there, > due to the widespread acceptance of binary number format (0b1010101) and > the growing demand for backwards compatibility I've started to work on > support for Roman Numerals (I, II, III, ...) > > As you might know, this format cannot be strictly parsed from left to > right or right to left, as several number values need a look-ahead > before being able to compute them (like IV), so my naive first > implementation splits the string into tokens (like in 1990 = MCMXC => > M,CM,XC => 1000,900,90) then simplifying those 3 on their own, then > adding the results, but I'm not sure this could kill performance if > calculated inside zend_language_scanner.l. Thanks for the work on it. I really appreciated and would love to see roman numberes finally get implemented. I think a fair asusmption is that there is a certain ordering. First add numbers unless you encouter a higher or lower number: (1) in case current number == previous number, add it to your temp buffer (2) in case current number < previous number, add it to your temp buffer (3) in case current number > previous number, substract it from temp buffer Obviously you need to check if hte number is valid too: IIVM is obviously wrong But i think this is a good start.