Re: Grammar for roman numerals

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
1 Apr 2007 08:55:42 -0400

          From comp.compilers

Related articles
Grammar for roman numerals msully4321@gmail.com (2007-03-27)
Re: Grammar for roman numerals martin@gkc.org.uk (Martin Ward) (2007-03-29)
Re: Grammar for roman numerals boldyrev+nospam@cgitftp.uiggm.nsc.ru (Ivan Boldyrev) (2007-03-29)
Re: Grammar for roman numerals mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2007-03-30)
Re: Grammar for roman numerals martin@gkc.org.uk (Martin Ward) (2007-03-30)
Re: Grammar for roman numerals mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2007-04-01)
Re: Grammar for roman numerals DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-04-01)
Re: Grammar for roman numerals alex.habar.nam@gmail.com (whiskey) (2007-04-06)
Re: Grammar for roman numerals dickey@saltmine.radix.net (Thomas Dickey) (2007-04-06)
Re: Grammar for roman numerals mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2007-04-06)
Re: Grammar for roman numerals DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-04-08)
| List of all articles for this month |

From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: 1 Apr 2007 08:55:42 -0400
Organization: cbb software GmbH
References: 07-03-095 07-03-107
Keywords: parse
Posted-Date: 01 Apr 2007 08:55:42 EDT

On 29 Mar 2007 23:05:56 -0400, Ivan Boldyrev wrote:


> On 9791 day of my life msully wrote:
>> One of the exercises I am doing is writing a grammar for roman
>> numerals.
> ...
>> Comments?
>
> Now rewrite the grammar as a regular expression :)


Not in "regulars", but the following more or less obvious pattern


NOEMPTY
( ['M'['M'['M']]]
    ['C'['D'|'M'|'C'['C']] | 'D'['C'['C'['C']]]]
    ['X'['L'|'C'|'X'['X']] | 'L'['X'['X'['X']]]]
    ['I'['V'|'X'|'I'['I']] | 'V'['I'['I'['I']]]]
)


should do the trick. More complex were to use immediate assignments for
evaluation of the numeral's value it gets matched. But it is also doable.
Though a hand-written scanner would be faster and cleaner.


--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


Post a followup to this message

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