# No subject

Wed Apr 10 17:18:51 CEST 2013

```ideal. =C2=A0We have the patterns<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 i{1,3} | iv | vi{1,3} | ix =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0units<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 x{1,3} | xl | lx{1,3} | xc =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0tens<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 c{1,3} | cd | dc{1,3} | cm =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0hundreds<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 m{1,3} | m=E2=86=81 | =E2=86=81m{1,3} | m=E2=86=
=82 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0thousands<br>
so we want to write a grammar rule like<br>
<br>
<br>
roman(N) --&gt;<br>
=C2=A0 =C2=A0 group(&#39;m&#39;, &#39;=E2=86=81&#39;, &#39;=E2=86=82&#39;, =
M),<br>
=C2=A0 =C2=A0 group(&#39;c&#39;, &#39;d&#39;, &#39;m&#39;, C),<br>
=C2=A0 =C2=A0 group(&#39;x&#39;, &#39;l&#39;, &#39;c&#39;, X),<br>
=C2=A0 =C2=A0 group(&#39;i&#39;, &#39;v&#39;, &#39;x&#39;, I),<br>
=C2=A0 =C2=A0 {N is M*1000 + C*100 + X*10 + I}.<br>
<br>
group(U, F, T, N) --&gt;<br>
=C2=A0 =C2=A0 ( [U,T] =C2=A0 =C2=A0 -&gt; {N =3D 9}<br>
=C2=A0 =C2=A0 ; [U,F] =C2=A0 =C2=A0 -&gt; {N =3D 4}<br>
=C2=A0 =C2=A0 ; [U,U,U] =C2=A0 -&gt; {N =3D 3}<br>
=C2=A0 =C2=A0 ; [U,U] =C2=A0 =C2=A0 -&gt; {N =3D 2}<br>
=C2=A0 =C2=A0 ; [U] =C2=A0 =C2=A0 =C2=A0 -&gt; {N =3D 1}<br>
=C2=A0 =C2=A0 ; [F,U,U,U] -&gt; {N =3D 8}<br>
=C2=A0 =C2=A0 ; [F,U,U] =C2=A0 -&gt; {N =3D 7}<br>
=C2=A0 =C2=A0 ; [F,U] =C2=A0 =C2=A0 -&gt; {N =3D 6}<br>
=C2=A0 =C2=A0 ; [F] =C2=A0 =C2=A0 =C2=A0 -&gt; {N =3D 5}<br>
=C2=A0 =C2=A0 ).<br>
<br>
using DCG notation. =C2=A0This is not context-free. =C2=A0It is an<br>
attribute grammar with attributes passed down the parse<br>
tree (U, F, T) and passed up the parse tree (N).<br>
<br>
Parser combinators are the easy way to do this in Haskell;<br>
see &#39;parsec&#39; or any number of parser combinator tutorials.<br>
<br>
For that matter, it&#39;s pretty trivial to do this particular<br>
one with plain code that pretty much mirrors the structure<br>
shown above. =C2=A0Just write something that takes (as many<br>
arguments as you want) then a list of characters coming in<br>
and returns a pair with a computed answer and the remaining<br>
characters. =C2=A0But wait! =C2=A0That _is_ a parser combinator!<br>
I guess parser combinators can&#39;t be that hard after all (:-).<br>
<br>
Good luck finding the five thousand character (=E2=86=81) or the<br>
ten thousand character (=E2=86=82) or any of the other Unicode<br>
&quot;I&#39;m not a letter, no, honest, I&#39;m really not, I&#39;m a<br>
Roman numeral&quot; characters on your keyboard.<br>
<div class=3D"HOEnZb"><div class=3D"h5"><br>
<br>
_______________________________________________<br>