PTG Assignment 3: Attribute Grammars with JastAdd

Create a table formatting application using JastAdd. It should output a formatted table where each column has a fixed width. The input table may be specified using basic HTML tags.

An example input can be the following:

    <table>
    <tr>
      <td>Top-left</td> <td>Top-middle</td> <td>Top-right</td>
    </tr>
    <tr>
      <td>Another cell on the left</td> <td>Table center</td> <td></td>
    </tr>
    <tr>
      <td>1</td> <td>2</td> <td>3</td>
    </tr>
    </table>

The expected output for this table is:

    Top-left                 Top-middle   Top-right
    Another cell on the left Table center 
    1                        2            3

Steps

Proceed according to the following plan:

Designing the AST

A basic JastAdd data structure should be designed for the table, tr, and td tags that exist in this table language. Implement this in the abstract grammar formalism that can be used as input to Jastadd and generate conforming Java files.

Unit Testing

Rather than parsing the input, for this exercise it is sufficient to use hard-coded tables constructed using the data structure you designed in the previous step. Define a series of JUnit unit tests to confirm your application is working.

Attributes

Using attributes, compute the maximum width of all cells in a column. One approach may be to parametrize attributes with the index of the column they apply to (e.g., widthOf(int i)).

Print the table

Define a print() method for each of the elements of the language, that prints the table to System.out.

Required software

JastAdd, which is available from www.jastadd.org. Ant and Java, which are available from the Apache and Sun websites.

Additional information

The course literature includes examples of the table formatting problem in Eli.

Submission

Submit your complete solution and unit tests by April 20th.

Contributions by SanderVermolen LennartKats