37static int sentenceTokens3[] = { 11, 12, 17, 9, 36, 12, 1, 6, 20,
PERIOD,
EOL };
75 static char buffer[256] = { 0 };
77 memset(buffer, 0,
sizeof(buffer));
80 for (
size_t index = 0; tokens[index] !=
EOL; ++index)
82 char numBuffer[6] = { 0 };
83 int num_chars = snprintf(numBuffer,
sizeof(numBuffer),
"%3d", tokens[index]);
86 int errorCode = errno;
87 printf(
" Error (%d)! snprintf() failed in _TokensToString(): %s!\n", errorCode,
91 strcat(buffer, numBuffer);
92 if (tokens[index + 1] !=
EOL)
126 printf(
"\nInterpreter Exercise\n");
128 for (
size_t sentenceIndex = 0;
_sentenceTokenLists[sentenceIndex] != NULL; ++sentenceIndex)
142 printf(
" %-50s ==> \"%s\"\n", tokensAsString, sentence.
string);
static int sentenceTokens2[]
Represents the sentence: "Would you have a will to do that?".
static int * _sentenceTokenLists[]
A list of pre-defined token lists. Each token list represents a single sentence constructed from the ...
void Interpreter_Exercise(void)
Example of using the Interpreter Pattern.
static int sentenceTokens3[]
Represents the sentence: "For not you I would not be in this.".
static int sentenceTokens5[]
Represents the sentence: "By her will we will do it.".
static int sentenceTokens4[]
Represents the sentence: "We say that but would you say it?".
static const char * _TokensToString(int *tokens)
Helper function to convert a list of ints to a string representation.
static int sentenceTokens0[]
Represents the sentence: "What do you say to that?".
static int sentenceTokens1[]
Represents the sentence: "Will you be the one to be there?".
bool Interpreter_Interpret(const int *tokenList, DynamicString *output)
This function is a simple interpreter.
Declaration of the Interpreter_Interpret() function used in the Interpreter Pattern.
@ EOL
Marker for end of a token list.
Declaration of the Interpreter_Exercise() function as used in the Interpreter Pattern.
void DynamicString_Clear(DynamicString *string)
Clear a DynamicString object, releasing any allocated memory. Resets to an empty string.
Represents a string that can be grown dynamically.
char * string
The string that can grow.