Programming Project

This project is due by the start of class on Tuesday, April 22. You may work by yourself or in pairs. You may use any language you wish for this assignment; however, if you want to use something other than C++, Java, or Smalltalk, you should check with me first (since this is intended to be an exercise in object-oriented programming).

The task is to implement a program which can display tables formatted with a subset of HTML. Your program should ask for the name of a file containing the HTML description of a table, and then display the formatted table on the screen. For example, if the program were given the following file as input:

<TABLE>
  <TR> <TD> Hello </TD> <TD> World </TD> </TR>
  <TR>
    <TD> <TABLE>
        <TR> <TD> Line One </TD> </TR>
        <TR> </TR>
        <TR> <TD> Line Two </TD> <TD> More </TD> </TR>
    </TABLE> </TD>
    <TD> This is a test </TD>
  </TR>
  <TR> <TD> </TD> <TD> Done </TD> </TR>
</TABLE>
then the output should look something like:
Hello           World
Line One        This is a test

Line Two  More
                Done
You are free to decide exactly how much space you want to include between rows and between items on a row. You may also choose to center the items vertically or horizontally; in this example, I have aligned the items to the left and top of each cell of the table (which is probably the easiest choice).

Here is a grammar giving the syntax of the input:

Table $ \rightarrow$ <TABLE> Rows </TABLE>
Rows $ \rightarrow$ Row Rows
  |  
Row $ \rightarrow$ <TR> Cells </TR>
Cells $ \rightarrow$ Cell Cells
  |  
Cell $ \rightarrow$ <TD> Item </TD>
Item $ \rightarrow$ Table
  | Text
In words, this says that a table consists of a matched pair of <TABLE>/</TABLE> tags surrounding zero or more rows. Each row consists of a matched pair of <TR>/</TR> tags surrounding zero or more cells. Each cell contains either plain text (which may include spaces but no tags--you may assume that the text does not contain the character <) or an entire table, surrounded by <TD>/</TD> tags.

To make your life easier, you may assume that all tags will be surrounded by whitespace (spaces, tabs, or newlines); this means that you only have to read in a sequence of words separated by spaces.

The basic rule of formatting is that all the rows of a table have their corresponding columns aligned with each other. That is, a row's nth cell will start at the same column position as the nth cells in all the other rows of the table (provided they have at least n cells; some rows may be shorter than others). A cell containing text will display that text all on one line (so you don't have to do any line breaking; don't worry about lines getting too long). A cell containing another table will take on the width and height of that table.