Práctica: Traducción de invitation a HTML

Esta práctica es continuación de la práctica un lenguaje para componer invitaciones especificada en la sección 1.8.

El objetivo es traducir la entrada escrita en el lenguaje de invitaciones a HTML. La traducción del ejemplo anterior debería ser parecida a esta:
pl@nereida:~/Lpl0910/Practicas/161009/src$ cat -n invitation.xml
 1  <?xml version="1.0"?>
 2  <!DOCTYPE invitation SYSTEM "invitation.dtd">
 3  <invitation>
 4  <!-- ++++ The header part of the document ++++ -->
 5  <front>
 6  <to>Anna, Bernard, Didier, Johanna</to>
 7  <date>Next Friday Evening at 8 pm</date>
 8  <where>The Web Cafe</where>
 9  <why>My first XML baby</why>
10  </front>
11  <!-- +++++ The main part of the document +++++ -->
12  <body>
13  <par>
14  I would like to invite you all to celebrate
15  the birth of <emph>Invitation</emph>, my
16  first XML document child.
17  </par>
18  <par>
19  Please do your best to come and join me next Friday
20  evening. And, do not forget to bring your friends.
21  </par>
22  <par>
23  I <emph>really</emph> look forward to see you soon!
24  </par>
25  </body>
26  <!-- +++ The closing part of the document ++++ -->
27  <back>
28  <signature>Michel</signature>
29  </back>
30  </invitation>
pl@nereida:~/Lpl0910/Practicas/161009/src$ cat invcss.html.save
<HTML>
<HEAD>
<TITLE> Invitation (sgmlpl/CSS formatting) </TITLE>
<LINK href="invit.css" rel="style-sheet" type="text/css">
<!-- 24 August 1998 mg -->
</HEAD>
<BODY>
<H1>INVITATION</H1>
<P><TABLE>
<TBODY>
<TR><TD class="front">To: </TD>
<TD>Anna, Bernard, Didier, Johanna</TD></TR>
<TR><TD class="front">When: </TD>
<TD>Next Friday Evening at 8 pm</TD></TR>
<TR><TD class="front">Venue: </TD>
<TD>The Web Cafe</TD></TR>
<TR><TD class="front">Occasion: </TD>
<TD>My first XML baby</TD></TR>
</TBODY>
</TABLE>
<P>
I would like to invite you all to celebrate
the birth of <EM>Invitation</EM>, my
first XML document child.
</P>
<P>
Please do your best to come and join me next Friday
evening. And, do not forget to bring your friends.
</P>
<P>
I <EM>really</EM> look forward to see you soon!
</P>
<P CLASS="signature">Michel</P>
</BODY>
</HTML>
Para ver el resultado en su navegador visite el fichero invitation.html

Su programa deberá producir un Abstract Syntax Tree. Los nodos serán objetos. Cada clase (FRONT, TO, etc.) deberá de disponer de un método translate.

Para simplificar el proceso de traducción a HTML se sugiere utilizar una hoja de estilo parecida a la siguiente (tomada de la seción 7.4.4 del citado libro de Goosens):

pl@nereida:~/Lpl0910/Practicas/161009/src$ cat -n invit.css
 1  /* CSS stylesheet for invitation1 in HTML */
 2  BODY {margin-top: 1em;     /* global page parameters */
 3        margin-bottom: 1em;
 4        margin-left: 1em;
 5        margin-right: 1em;
 6        font-family: serif;
 7        line-height: 1.1;
 8        color: black;
 9  }
10  H1   {text-align: center;  /* for global title   */
11        font-size: x-large;
12  }
13  P    {text-align: justify; /* paragraphs in body */
14        margin-top: 1em;
15  }
16  TABLE { border-width: 0pt }
17  TBODY { border-width: 0pt }
18  TD[class="front"] {        /* table data in front matter */
19        text-align: left;
20        font-weight: bold;
21  }
22  TD.front {        /* table data in front matter */
23        text-align: left;
24        font-weight: bold;
25  }
26  EM   {font-style: italic;  /* emphasis in body   */
27  }
28  P.signature {     /* signature          */
29        text-align: right;
30        font-weight: bold;
31  }

Véase también:

Casiano Rodríguez León
2009-12-09