Semantic validation

In the semantic validation step, the ZurkParser should not merely parse the GAME FILE, but should compile the same data structures that the Zurk engine would employ. Rather than entering into the user-interface loop, however, ZurkParser in semantic validation mode will dump the contents of the data structures in a Scheme-like format.

The data structure dump MUST obey the following rules:

  1. Dump all ROOM declarations first, followed by OBJECT declarations, and finally ACTION declarations.
  2. Dump the contents of all structures in the order declared in the WDL grammar (Section 4.2.2.3).
  3. All structures MUST be dumped in the following, Scheme-like prefix syntax:
            (TYPE prop1 ... propN)
    
    followed by a newline, where TYPE is the type of the structure (ROOM, ACTION, ROOMREF, AND, OR, NOT, EQ, etc.) and prop1...propN are the properties associated with that structure. E.g., for a ROOM object, its properties are NAME, DESCRIPTION, OBJECTS, and MOVES. All types MUST be printed in upper-case.
Data structures MUST be dumped only after the entire parse is completed. Data structures MUST NOT be dumped if any syntax error is encountered during parsing; instead, a syntax error (of the same type printed by the syntactic analyzer) MUST be printed and the semantic validation step exited.

In addition, the semantic validator MUST verify the following:

  1. All ROOM, ACTION, and OBJECT declarations are unique.
  2. All referenced things (ROOMs, OBJECTs, VARIABLEs, etc.) are declared once and only once in the GAME FILE. For VARIABLEs, the absolute name must be used to verify declarations (e.g., to distinguish between rose.color and door.color).
  3. Every OBJECT is assigned to one and only one LOCATION.
  4. All relative lval references in an ACTION obey the declared arity of that ACTION.
  5. That no condstatement in any MOVE employs any relative lvals. (Since MOVEs have arity 0, this is a consequence of the above.)
  6. Reachability: that every ROOM is referenced as a target in at least one MOVE or ACTION. (Note that such a reference does not guarantee that the ROOM is reachable, but only that it is potentially reachable.)
A notification MUST be printed, after the data structure dump, only if one or more of these conditions is violated. The format of the notification is up to the designer, but it MUST at least include the nature of the violation and as much detail about the location as possible. E.g., ERROR: condstatement references $3, but arity of Action(get) is only 1. Or, ERROR: Room(garden) references ObjRef(rake), but no Object(rake) has been declared.

An example of a semantic analysis is given in Appendix C.

Terran Lane 2005-02-28