GDL Exercise Notes

The following code example shows the index tree that the parser generates for all of the GDL exercises.

      <:ROOT2>
    *PFeature : InputTray    <:INPUTTRAY_FEATURE>
        *POption : Lower    <:INPUTTRAY_OPTION2>
            *Capacity    <:TRAY_CAPACITY>
            *Command    <:ACOMMAND>
            *Name    <:INPUTTRAY_OPT_NAME>
        *POption : Upper    <:INPUTTRAY_OPTION2>
            *Capacity    <:TRAY_CAPACITY>
            *Command    <:ACOMMAND>
            *Name    <:INPUTTRAY_OPT_NAME>
        *DefaultOption    <:DEFAULT_OPT>
        *Name    <:NAME>
    *PFeature : PaperSize    <:PAPERSIZE_FEATURE>
        *POption : Custom    <:CUST_PAPERSIZE_OPTION>
            *MinSize    <:MIN_SIZE>
            *MaxSize    <:MAX_SIZE>
            *Command    <:ACOMMAND>
            *Name    <:PAPER_SIZE_OPT_NAME>
        *POption : OEMName_Special_size    <:OEM_PAPERSIZE_OPTION>
            *OEM_Info    <:OEM_INFO>
            *PaperSize    <:PAPERDIMENSIONS>
            *Command    <:ACOMMAND>
            *Name    <:PAPER_SIZE_OPT_NAME>
        *POption : A4    <:PREDEFINED_PAPERSIZE_OPTION>
            *PaperSize    <:PAPERDIMENSIONS>
            *Command    <:ACOMMAND>
            *Name    <:PAPER_SIZE_OPT_NAME>
        *POption : Legal    <:PREDEFINED_PAPERSIZE_OPTION>
            *PaperSize    <:PAPERDIMENSIONS>
            *Command    <:ACOMMAND>
            *Name    <:PAPER_SIZE_OPT_NAME>
        *POption : Letter    <:PREDEFINED_PAPERSIZE_OPTION>
            *PaperSize    <:PAPERDIMENSIONS>
            *Command    <:ACOMMAND>
            *Name    <:PAPER_SIZE_OPT_NAME>
        *DefaultOption    <:DEFAULT_OPT>
        *Name    <:NAME>
    *PFeature : random    <:PFEATURE >
        *POption : First    <:GENERIC_OPTION>
            *Command    <:ACOMMAND>
            *Name    <:NAME>
        *DefaultOption    <:DEFAULT_OPT>
        *Name    <:NAME>

The *Name and *POption entries map to several templates, each with different semantics. For example, *Name maps to NAME, INPUTTRAY_OPT_NAME, or PAPER_SIZE_OPT_NAME. *POption maps to GENERIC_OPTION, PREDEFINED_PAPERSIZE_OPTION, CUST_PAPERSIZE_OPTION, OEM_PAPERSIZE_OPTION, or INPUTTRAY_OPTION2. If the template structure has been defined correctly, the parser following its templatization rules will find the most appropriate template.

Note   These exercises establish some basic templates and subsequently derived variants as the schema became more detailed. This process mimics the way a schema evolves in real-life. Inheritance enabled the exercise schema to be extended without changing any previously defined templates. This feature enables third parties to extend the master schema and also ensures that any third-party schema extension remains compatible with users of the original master schema.

The exercise answers that are shown are not unique. For example, you could have derived the templates MIN_SIZE and MAX_SIZE from PAPERDIMENSIONS in the following manner.

*Template:  MIN_SIZE
{
    *Name: "*MinSize"
    *Inherits: PAPERDIMENSIONS
}
*Template:  MAX_SIZE
{
    *Name: "*MaxSize"
    *Inherits: PAPERDIMENSIONS
}

Note that the PAPER_SIZE_OPT_NAME and INPUTTRAY_OPT_NAME templates inherit from the template NAME and also redefine the *Name entry.

The effect of redefining the *Name entry is to hide these derived templates from the inheritance tree that the base templates establish.

Typically, when a template declares NAME to be a *Member, this declaration implies that all templates that are derived from NAME are also *Members. However, derived templates with redefined *Name entries are excluded from the implied *Members list of derived templates. Without this exclusion, data entries that would have originally mapped to template NAME (for example, *Name appearing within a *Pfeature) would get mapped to INPUTTRAY_OPT_NAME (which is incorrect).

If you anticipate the specialization of NAME into PAPER_SIZE_OPT_NAME and INPUTTRAY_OPT_NAME during the original design of the schema, a different schema implementation would result simply by removing NAME from the *Members list of GENERIC_OPTION. This change would make it unnecessary to redefine *Name. A further design refinement would have NAME, PAPER_SIZE_OPT_NAME, and INPUTTRAY_OPT_NAME inheriting from a common virtual template, because that situation more accurately reflects the relationship between these keywords.