Sunday, February 5, 2017

Parsing in ZILF, part 3: From noun phrase to object

This is the third in a series of posts describing ZILF's parser. Read part 2 here.

In the second post, we covered noun phrases -- phrases like "all cubes except red" and "lamp, food, and bottle" that the player can type to refer to objects.

We also covered how the parser recognizes them and how it represents them in memory: the PARSE-NOUN-PHRASE routine scans the player's command and fills in a NOUN-PHRASE structure, which holds a list of adjective/noun pairs called OBJSPECs.

But how does the parser identify which objects the player is referring to?

After MATCH-SYNTAX finds a syntax line that matches the player's command, the FIND-OBJECTS routine combines the noun phrases with the find flag and search options from the syntax line, and decides what needs to be done for each object required by the syntax line.

There are a few possibilities, depending on what the player typed. It can:

  • match a noun phrase,
  • expand a pronoun,
  • supply a missing object,
  • ask the player to clarify,
  • or fail, printing an error message.