Lex Transform Example

This example show has Lex can be used to transform input from one format to another.

The input format is that of a textual spreadsheet. Each spreadsheet entry is numbered using an alphabetical character (indicating the row) and an integer (indicating the column). To make the task easier, we can assume several things. First there will not be more than 26 columns. Second, that the entries will be ordered in the obvious way, i.e. A1, followed by B1, ... then A2, followed by B2, etc. Third, there will only be one entry per line and that all entries exist in the file. Finally, we are going to assume that there are no spreadsheet equations.

An example input might be

A0="Name"
B0 = "SSN"
C0 = "HW1"
D0 = "HW2"
A1 = "Scott Smith"
B1 = "123-44-5678"
C1 = 82
D1 = 44.2
A2 = "Sam Sneed"
B2 = "999-88-7777"
C2 = 92
D2 = 84

For output, we what to generate the appropriate HTML table. In html, tables are surrounded by <table> ... </table>. Each row of the table is surrounded by <tr> ... </tr> and each entry in a row by <td> ... </td>. For the above input we would want to output:

<P>
<table>
<tr>
<td> Name </td>
<td> SSN </td>
<td> HW1 </td>
<td> HW2 </td>
</tr>
<tr>
<td> Scott Smith </td>
<td> 123-44-5678 </td>
<td> 82 </td>
<td> 44.2 </td>
</tr>
<tr>
<td> Sam Sneed </td>
<td> 999-88-7777 </td>
<td> 92 </td>
<td> 84 </td>
</tr>
</table>

When viewed with a viewer, this looks like:
Name SSN HW1 HW2
Scott Smith 123-44-5678 82 44.2
Sam Sneed 999-88-7777 92 84
Lex specification for the conversion and its makefile