Re: Question about parser implementation details

From: Date: Sun, 01 Apr 2012 20:28:44 +0000
Subject: Re: Question about parser implementation details
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 2012-04-01, Florian Anderiasch <[email protected]> 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.



Thread (6 messages)

« previous php.internals (#59309) next »