Re: Parsing Roman numbers

Martin Ward <>
Tue, 26 May 1992 11:15:29 GMT

          From comp.compilers

Related articles
Parsing Roman numbers (1992-05-22)
Re: Parsing Roman numbers (1992-05-23)
Re: Parsing Roman numbers (1992-05-24)
Re: Parsing Roman numbers (1992-05-24)
Re: Parsing Roman numbers (Martin Ward) (1992-05-26)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Martin Ward <>
Keywords: parse
Organization: Compilers Central
References: 92-05-126 92-05-131
Date: Tue, 26 May 1992 11:15:29 GMT (Henry Spencer) writes:
> Roman numerals are described by the regular expression
> M*(CM|DC{0,3}|CD|C{0,3})(XC|LX{0,3}|XL|X{0,3})(IX|VI{0,3}|IV|I{0,3})

My dictionary mentions IIC as an allowed representation for 98, also _any_
lower numerals can be used before a larger numeral to indicate
subtraction, eg: MXM = 1990, IIM = 999. There's also the older
representations (I) for M (with ((I)) for 10,000, (((I))) for 100,000
etc.) and )( for X.

For translating Roman numerals to arabic I would allow any sequence of
MDCLXVI, work from left to right keeping a running total, when you hit a
larger numeral than the previous one, scan from right to left a suitable
number of places, subtracting _twice_ the value of the numerals scanned.
Converting this algorithm into a single-pass algorithm is simple.

Compiling from arabic to roman numerals is more difficult because there are
many roman numeral representations of the same arabic number.


JANET: Internet (eg US):
or if that fails:
BITNET: UUCP:...!uknet!durham!Martin.Ward
[Enough already. There's a zillion different variants of roman numbers,
and no formal definition. Unfortunately, the archives of the appropriate
National Standards Organization, the RISI (Roman Imperial Standards
Institute, formerly the RRSI) were lost when their impressive marble Hall
of Records collapsed due to a calculation error by the architect. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.