next up previous
Next: Structure of the Input Up: Example Previous: Statement of the problem


Structure of the Output File

The header file to be output has the structure shown in Figure 2. Each box represents a component of the kind named in the box. The children of a box, taken in order, constitute the sub-components of that box. If a box contains an asterisk, it represents an arbitrary number of components of the given kind. You should convince yourself that Figure 2 does, indeed, describe the structure of the header file presented above.

Figure 2: Header File Structure

We can describe the text associated with each node of Figure 2 by the following declarative specification:

OutputText.ptg[3]:

HeaderFile:
  "int NumberOfSets = " $/*integer*/ ";\n\n"
  "char *NameOfSet[] = {\n"
  "  " $/*list of set names*/ "};\n\n"
  "int SizeOfSet[] = {\n"
  "  " $/*list of set sizes*/ "};\n\n"
  $/*sequence of sets*/
  "char **ValuesOfSet[] = {\n"
  "  " $/*list of set names*/ "};\n"

Set:
  "char *" $/*set name*/ "[] = {\n"
  "  " $/*list of set elements*/ "};\n\n"

Name:
  "SetOf_" $

Quoted:
  "\"" $ "\""

List:
  $ ",\n  " $

Seq:
  $ $
This macro is attached to a product file.

From this declarative specification, Eli will generate a module that exports functions named PTGHeaderFile, PTGSet, PTGName, PTGQuoted, PTGList and PTGSeq. PTGSet (for example) would be called with two arguments, one a PTGNode representing the name of the set and the other a PTGNode representing the list of quoted elements.

In addition to these functions, the module exports an output function PTGOut that takes a PTGNode as its argument and writes the text represented by that PTGNode on standard output. (Other output functions are also exported by the module.)


next up previous
Next: Structure of the Input Up: Example Previous: Statement of the problem
2007-05-18