Skip to content
/ roman Public

OCaml module and command line tool to convert a roman numeral to an integer and vice versa

License

Notifications You must be signed in to change notification settings

lindig/roman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roman - convert roman numerals to integer

This repository provides an OCaml module and minimal command line tool to convert modern roman numerals to integer and vice versa:

$ roman mmxv
2015
$ roman 1234
mccxxxiv

The command line tool recognizes integer and roman numerals and emits it after conversion to the opposite format.

The module accepts the syntax for modern roman numerals as defined by Wikipedia and detects illegal syntax like the following:

im 
xcc  
ic
imm
mxm
viiii
ivi

This little exercise was prompted by an article Radikale Objektorientierung: Teil 2: Verhalten prinzipiengeleitet verfeinern in OBJEKTspektrum issue 2/12015 that used conversion of roman numerals as an example for OO design. The code from that article is available on GitHub.

Build and Test

$ make
$ make test
$ make PREFIX=$(HOME) install 

The implementation is in roman.mll and uses ocamllex to build an automaton for recognising roman numerals. To use as a module, simply copy roman.mll and roman.mli into your own project. (I didn't bother yet to pack it up for Opam.)

Syntax

For the syntax of roman numerals recognised by the module, take a look at roman.mll where it is encoded as a regular expression:

(M|MM|MMM)?
(D?(C|CC|CCC)?|CD|CM)?
(L?(X|XX|XXX)?|XL|XC)?
(V?(I|II|III)?|IV|IX)?

Author

Christian Lindig lindig@gmail.com

License

This code is licensed under the BSD 2-clause license.

About

OCaml module and command line tool to convert a roman numeral to an integer and vice versa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published