Design Pattern Examples
Overview of object-oriented design patterns
Interpreter_Interpreter.h File Reference

Declaration of the Interpreter_Interpret() function used in the Interpreter Pattern. More...

Include dependency graph for Interpreter_Interpreter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __INTERPRETER_INTERPRETER_H__
 

Enumerations

enum  { PERIOD = 100 , QUESTION = 101 , EOL = -1 }
 Enum to define constants for tokens. More...
 

Functions

bool Interpreter_Interpret (const int *tokenList, DynamicString *output)
 This function is a simple interpreter.
 

Detailed Description

Declaration of the Interpreter_Interpret() function used in the Interpreter Pattern.

Definition in file Interpreter_Interpreter.h.

Macro Definition Documentation

◆ __INTERPRETER_INTERPRETER_H__

#define __INTERPRETER_INTERPRETER_H__

Definition at line 8 of file Interpreter_Interpreter.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Enum to define constants for tokens.

Enumerator
PERIOD 

Period.

QUESTION 

Question mark.

EOL 

Marker for end of a token list.

Definition at line 15 of file Interpreter_Interpreter.h.

Function Documentation

◆ Interpreter_Interpret()

bool Interpreter_Interpret ( const int *  tokenList,
DynamicString output 
)

This function is a simple interpreter.

The interpreter takes an array of integer tokens and converts each token into a word or punctuation mark. The interpreter then arranges the words into a space-separated list in a single string. In other words, the tokens are converted into a sentence, with the first word capitalized and no space between the last two "words" under the assumption the last word is actually a punctuation mark.

Interpreter Rules:

  1. Each token must be in the range of 0 through 39 (maximum number of words known by the interpreter) or must be 100 ('.') or 101 ('?').
  2. The word corresponding to the first token is always capitalized.
  3. A single space appears between each word.
  4. No space appears between the last two tokens.
Parameters
tokenListList of integer tokens to be interpreted. The list is assumed to be terminated by -1 (EOL).
outputA DynamicString object returning the sentence created through interpreting the tokens. Call DynamicString_Clear() when done with the string.
Returns
Returns true if the token list was interpreted successfully; otherwise, returns false, indicating an out of memory condition (or a NULL argument.

Definition at line 117 of file Interpreter_Interpreter.c.

References _InterpretToken(), DynamicString_Append(), EOL, and titlecase().

Referenced by Interpreter_Exercise().