Expand description

The Interpreter design pattern example module

The interpreter is a function that is fed a series of arrays containing integer tokens. Each token represents a single word or punctuation mark. The interpreter converts that array of tokens to an actual sentence by interpreting the meaning of the tokens.

This is a very simple interpreter that handles the first token in a special way and supports punctuation. It is an example of a linear interpreter where tokens can appear in any order (it’s up to the creator of the token list to make sure the outcome makes any sense).

Accessed through the interpreter_exercise() function.

Modules

  • Contains the interpreter function along with the InterpreterConstants enumeration, as used in the Interpreter design example.

Constants

  • Represents the sentence: “What do you say to that?”
  • Represents the sentence: “Will you be the one to be there?”
  • Represents the sentence: “Would you have a will to do that?”
  • Represents the sentence: “For not you I would not be in this.”
  • Represents the sentence: “We say that but would you say it?”
  • Represents the sentence: “By her will we will do it.”
  • A list of pre-defined token lists. Each token list represents a single sentence constructed from the 40 most common words in the English language. I don’t use all 40 words, though; that would be silly.

Functions