Grammar for roman numerals

msully4321@gmail.com
27 Mar 2007 09:27:36 -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)
[4 later articles]
| List of all articles for this month |
From: msully4321@gmail.com
Newsgroups: comp.compilers
Date: 27 Mar 2007 09:27:36 -0400
Organization: Compilers Central
Keywords: parse, question
Posted-Date: 27 Mar 2007 09:27:36 EDT

I am doing a self-taught independent study in compiler design through
my school using the Red Dragon book as a text. One of the exercises I
am doing is writing a grammar for roman numerals. I wanted to check my
grammar's correctness, but could not find any grammars on the internet
that covered all of the letters (up to M).


Here is my grammar (I allow an arbitrary number of Ms)


numeral -> thousands
thousands -> thous_part hundreds | thous_part | hundreds
thous_part -> thous_part M | M
hundreds -> hun_part tens | hun_part | tens
hun_part -> hun_rep | CD | D | D hun_rep | CM
hun_rep -> C | CC | CCC
tens -> tens_part ones | tens_part | ones
tens_part -> tens_rep | XL | L | L tens_rep | XC
tens_rep -> X | XX | XXX
ones -> ones_rep | IV | V | V ones_rep | IX
ones_rep -> I | II | III


Comments?


Thanks,
Mike Sullivan


Post a followup to this message

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