Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lindig/roman
OCaml module and command line tool to convert a roman numeral to an integer and vice versa
https://github.com/lindig/roman
Last synced: 4 days ago
JSON representation
OCaml module and command line tool to convert a roman numeral to an integer and vice versa
- Host: GitHub
- URL: https://github.com/lindig/roman
- Owner: lindig
- License: bsd-2-clause
- Created: 2015-05-02T07:13:50.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-14T19:14:20.000Z (over 9 years ago)
- Last Synced: 2023-03-25T00:24:19.271Z (over 1 year ago)
- Language: OCaml
- Homepage:
- Size: 180 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
mccxxxivThe 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](http://en.wikipedia.org/wiki/Roman_numerals) as defined by
Wikipedia and detects illegal syntax like the following:im
xcc
ic
imm
mxm
viiii
iviThis little exercise was prompted by an article [Radikale
Objektorientierung: Teil 2: Verhalten prinzipiengeleitet
verfeinern](http://www.sigs-datacom.de/fachzeitschriften/objektspektrum) 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](https://github.com/ralfw/TheArchitectsNapkinBlog).# Build and Test
$ make
$ make test
$ make PREFIX=$(HOME) installThe 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
# License
This code is licensed under the BSD 2-clause license.